BASIC PROGRAMMING REFERENCE MANUAL
.#
If many faultes in this book you fynde,
Yet think not the correctors blynde;
If Argos heere hymselfe had beene
He should perchance not all have seene.
Richard Shacklock. . . 1365
Published by
APPLE COMPUTER INC.
10260 Bandley Drive
Cupertino, California 95014
(408) 996-1010
All rights reserved. No part of this publication
may be reproduced without the prior written
permission of APPLE COMPUTER INC. Please call
(408) 996-1010 for more Information.
©1978 by APPLE COMPUTER INC. Reorder APPLE Product #A2L000J
(030-0013-03)
TABLE OF CONTENTS
xii overview
chapter!
GEniNG STARTED
2 [mTTiedia te-Executi on Cciniraands
2 Deferred-Execution ('.ommands
4 Number Format
5 Color Graphics Example
6 Print Format
7 Variable Names
9 IF... THEN
10 Another Color Example
11 FOR... NEXT
14 Arrays
15 GOSUB.. .KETURN
17 READ. ..DATA. . .RESTORE
18 Real, Integer and String Variables
19 Strings
23 More Color Craphics
25 High-Resolution Color Graphics
CHAPTER 2
DEFINITIONS
3(3 Syntactic Definitions and Abbreviations
36 Rules for Evaluating Expressions
36 Conversion of Types
36 Execution Modes
CHAPTER 3
SYSTEM AND UTILITY COMMANDS
j8 LOAD mid SAVE
38 NEW
38 RUN
39 STOP, END, cLrl C, reset and CONT
40 TRACE and NOTRACE
40 PEEK
4 1 POKE
41 WAIT
4 3 CALL
43 HIMEM:
44 LOMEM:
45 USR
III
CHAPTER
EDITING AND FORMAT- RELATED
COMMANDS
4
In CliapCer 3, also see Ctrl C.
48 LIST
49 DEL
50 REM
50 VTAB
50 HTAB
51 TAB
51 POS
52 SPC
52 HOME
52 CLEAR
53 FRE
53 FLASH, INVERSE and NORMAL
54 SPEED
54 esc A, esc B, esc C and esc D
55 repeat
55 right arrow and left arrow
55 Ctrl X
IV
CHAPTER 5
ARRAYS AND STRINGS
'iH DIM
59 LEN
59 SIRS
59 VAL
60 CHR$
f)0 ASC
6CI LEFTS
(il RIGHTS
61 ;iIDS
62 STORE and RFXAI.L
CHAPTER 6
INPUT/OUTPUT COMMANDS
In Chapter 3, also see LOAD and SAVE;
in Chapter 5, see STORE and RECALL.
66
ItJI'UT
67
GLT
68
DATA
69
READ
n
RESTORE
n
PRIST
71
IN#
72
VV.il
72
LET
73
DI!F FN
VI
CHAPTER
COMMANDS RELATING TO FLOW
OF CONTROL
7
76
(.Oil)
76
IF... THEN and IF.
..GOTO
78
FOR...TO...STKP
79
NEXT
79
cnsuK
80
RKTUKN
80
POI'
81
ON. ..ClflTO and ON..
. .COSUB
81
ONERR COTO
82
RESUME
VII
CHAPTER 8
GRAPHICS AND GAME CONTROLS
84 TKXT
Low Resolutiun CJraphics
84 GR
85 COLOR
85 PLOT
ah HLIN
«(S VLIN
87 SCRN
High-res.-iUuion Graphics
87 HGR
88 HGR 2
89 HCOLOR
89 HPLOr
Game Controls
90 PDL
VIII
CHAPTER 9
HIGH-RESOLUTION SHAPES
92
How to Create a Shape Table
97
Saving a Shape Table
97
Using a Shape Table
98
DRAW
98
XDRAW
99
ROT
99
SCALE
99
SHLOAD
IX
CHAPTER i
SOME MATH FUNCTIONS
102 The built-in functions SIN, COS, TAN,
ATN, INT, RND, SGN, ABS, SOR, EXP, LOG
103 Derived Functions
APPENDICES
106
110
1 15
ua
120
121
122
124
126
128
138
140
142
144
Appendix A
Appendix B
Appendix C
Appendix D
Appendix E
Appendix F
Appendix G
Appendix H
Appendix I
Appendix J
Appendix K
Appendix L
Appendix M
Appendix N
Appendix 0:
Getting APPLESOFT BASIC up
Program Editing
Krror Messages
Space Savors
Speeding Up Vour PrDgram
Decimal Tokens for Keywords
Reserved \Jords In APPLESOFT
Converting BASIC Programs to APPLESOFT
Memory Map (see also page 137)
PFEKs, POKES and CALLs
ASCII Character Codes
APPLESOFT Zero Page Usage
Differences Between APPLESOFT and Integer BASIC
Alphabetic Glossary of Syntactic Definitions
and Abbreviations
Summarv of APPLESOFT ComTnands
162 INDEX
Inside Back Cover:
Alphabetized Index of APPLESOFT Commands
XI
OVERVIEW
INTRODUCTION
APPLESOFT II BASIC is APPLE'S very much extended BASIC language. BASIC has
been extended because there are many features on the APPLE II computer that
just aren't available on other computers that use BASIC. By adding a few
new words to the BASIC language, these features are Immediately available to
anyone using APPLESOFT. Among the features supported by APPLESOFT are
apple's color graphics, high-resolution color graphics and the direct analog
inputs (the game controllers).
Another feature of APPLESOFT is this manual. It is not a self-teaching
manual, since APPLE provides a separate manual (the APPLE II BASIC
Programming Manual ) which will help you learn to program even if you
have never touched a computer before. This manual assumes that you know how
to program in BASIC and just wish to learn the additional features offered
by APPLESOFT. Chapter 1 (GETTING STARTED) is a quick run-through of what
the language has to offer. The rest of the manual is a careful and exact
description of every statement in the language and how each statement works.
To help save you the frustration and annoyance that some manuals can cause,
this manual points out places where programming errors can cause you
difficulty. Special symbols call your attention to these points.
The method used to describe APPLESOFT is almost a simple language in itself.
You will find that, after a few moments getting used to it, it will speed
your understanding of exactly what is legal and illegal in the language.
You will not be left with any nagging doubts about the interpretation of a
sentence, as can happen with pure English descriptions.
Advanced programmers will find this manual especially helpful. Beginning
programmers are reminded that they will soon no longer be beginners, and
will appreciate the extra effort APPLE has made to provide an unusually
complete manual. To be sure, a thicker manual looks more formidable, but
when you need the Information, you will be glad that we took the time and
space to put it in.
USING THIS MANUAL
This reference manual assumes you have a minimal working knowledge of the
programming language BASIC. If you're unfamiliar with BASIC, the APPLE
II BASIC Programming Manual can provide an introduction: it covers a
version of BASIC which is much like APPLESOFT II, but simpler.
We recommend that you have APPLESOFT II BASIC (usually referred to as
APPLESOFT) up and running when you consult this manual, so that you can try
out on your computer anything the manual describes or suggests. If
APPLESOFT is running on your system, the APPLESOFT prompt character ( ] )
will be displayed. See Appendix A for an explanation of how to get
APPLESOFT loaded into your computer.
XII
There are two terms you'll need to know when reading this manual. The word
"syntax" refers to the structure of a computer command, the order and
correct form of the command's various parts. The word "parse" refers to the
way in which the computer attempts to interpret what you type, picking out
the various parts of the computer commands in order to execute them. For
example, APPLESOFT'S syntax allows you to type
12X5=4*3*2
When APPLESOFT parses this input, it first picks out 12 as the program line
number, then interprets X5 as an arithmetic variable name. Finally,
APPLESOFT evaluates 3^2 as 9, then multiplies by 4, and assigns the value 36
to the variable whose name is X5.
Chapter 1 provides an overview of many APPLESOFT commands, for those who
have had little experience programming in BASIC. Many primary concepts are
introduced, using examples that you can type into the computer. Appendix B
gives pointers on editing APPLESOFT programs.
The notation introduced at the beginning of Chapter 2 is used to describe
APPLESOFT'S syntax concisely and unambiguously. It will save you time and
effort in understanding how the commands must be structured. You don't need
to use this notation yourself, but it will help you answer many questions
not specifically discussed in the text. For Instance, square brackets ( [
and ] ) are used to indicate optional portions of a command; curly brackets
( < and } ) are used to indicate those portions that may be repeated. So
[LET] C = 3
indicates that the word LET is optional and may be omitted. And
REM [{character)]
indicates that the REMark command consists of the word REM optionally
followed by one or more characters.
The syntactic abbreviations and definitions in the first part of Chapter 2
are presented in a logical order for those who want to see how we've built
up our system of symbols and definitions. You may prefer to ignore these
symbols and definitions until you encounter one in the text. At that time,
you can refer to the alphabetized glossary of syntactic terms given in
Appendix N.
Chapters 3 through 10 present detailed explanations of APPLESOFT'S commands,
grouped by subject matter. If you're interested in finding out about a
specific command, the alphabetized index on the inside of the back cover
will tell you where to look. Additional reference material not covered in
the chapters can be found in the appendices.
At some places you'll see the symbol
^
preceding a paragraph. This symbol indicates an unusual feature to which
you should be alert.
The symbol
(Eff-l
precedes paragraphs describing situations from which APPLESOFT may be unable
to recover. You will lose your program and will probably have to re-start
APPLESOFT.
XIII
GEniNG STARTED
2 Immediate-Execution Commands
2 Deferred-Execution Commands
4 Number Format
5 Color Graphics Example
6 Print Format
7 Variable Names
9 IF. ..THEN
10 Another Color Example
11 FOR... NEXT
14 Arrays
15 GOSUB... RETURN
17 READ... DATA. ..RESTORE
18 Real, Integer and String Variables
19 Strings
23 More Color Graphics
25 High-Resolution Color Graphics
IMMEDIATE -EXECUTION COMMANDS
Try typing the following:
PRINT 10-4
and then press the key marked RETURN.
APPLESOFT II will immediately print
6
The PRINT statement you typed was executed as soon as you pressed the RETURN
key. APPLESOFT evaluated the formula after the PRINT and then typed out its
value, in this case 6,
Now try typing this:
PRINT 1/2,3*10
( * means multiply, / means divide).
When you press the RETURN key, APPLESOFT will print:
.5 30
As you can see, APPLESOFT does division and multiplication, as well as
subtraction. Note how a comma ( , ) was used in the PRINT command to print
two values instead of Just one. The use of the comma with the PRINT command
divides the 40-character line into 3 columns or "tab fields." See the
discussion of tab fields in Chapter 6, under the PRINT command.
DEFERRED -EXECUTION COMMANDS
Commands such as the PRINT statements you have just typed are called
"immediate-execution" commands. There is another type of command called a
"deferred-execution" command. Every deferred-execution command begins with
a "line number". A line number is an integer from to 63999.
Try typing the following lines:
10 PRINT 2+3
20 PRINT 2-3
(Remember, each line must be terminated by pressing the RETURN key.)
A sequence of deferred-execution commands is called a "program." Instead of
executing deferred-execution statements Immediately, APPLESOFT BASIC stores
deferred-execution commands in the APPLE'S memory. Vfhen you type RUN,
APPLESOFT first executes the stored statement having the lowest line number,
then the statement with the next higher line number, etc., until the
complete program has been executed.
Suppose you type RUN now (remember to press the RETURN key at the end of
each line you type):
RUN
APPLESOFT will now display on your TV:
5
-1
In the previous example, we typed line 10 first and line 20 second.
However, it makes no difference in what order you type deferred-execution
statements. APPLESOFT always puts them Into correct numerical order
according to their line numbers.
To see a listing of the complete program currently in memory, with the
statements arranged in their correct order, type
LIST
APPLESOFT will reply with
10 PRINT 2+3
20 PRINT 2-3
Sometimes it is desirable to delete a line of a program altogether. This is
accomplished by typing the line number of the line you wish to delete,
followed only by a press of the RETL'RN key.
Type the following:
10
LIST
APPLESOFT will reply with;
20 PRINT 2-3
You have now deleted line 10 from the program. There is no way to get it
back. To insert a new line 10, just type 10 followed by the new statement
you want APPLESOFT to execute.
Type the following;
10 PRINT 2*3
LIST
APPLESOFT will reply with
10 PRINT 2*3
20 PRINT 2-3
There is an easier way to replace line 10 than deleting it and then
inserting a new line. You can do this by just typing the new line 10 (and
pressing the RETURN key, of course). APPLESOFT automatically throws away
the old line 10 and replaces it with the new one.
Type the following:
10 PRINT 3-3
LIST
APPLESOFT will reply with:
10 PRINT 3-3
20 PRINT 2-3
It is not recommended that program lines be numbered consecutively: it may
be necessary, later on, to insert a new line between two existing lines. An
increment of 10 between line numbers is generally sufficient.
If you want to erase the complete program currently stored in memory, type
NEW
If you are finished running one program, and are about to begin a new one,
be sure to type NEW first. This should be done to prevent a mixture of the
old and new programs.
Type the following:
NEW
APPLESOFT will reply with the prompt character:
]
Now type
LIST
APPLESOFT will reply with
]
showing that your previous program is no longer stored in memory.
NUMBER FORMAT
We will digress for a moment to explain the format of numbers printed by
APPLESOFT BASIC. Numbers are stored internally to over nine digits of
accuracy. When a number is printed, only nine digits are shown. Every
number may also have an exponent (a power-of-ten scaling factor).
In APPLESOFT BASIC, "real precision" (also called "floating point") numbers
must be in the range from -1*10'"38 to 1*10~38, or you risk getting an error
message. Using addition or subtraction, you may sometlraes be able to
generate numbers as large as 1.7*10"38 without the error message. A number
whose absolute value is less than about 3*10^-39 will be converted to zero
by APPLESOFT. In addition to these limitations, true integer values must be
in the range from -32767 to 32767.
When a number is printed, the following rules are used to determine the
exact format:
1) If the number is negative, a minus sign (-) is printed.
2) If the absolute value of the number is an integer in
the range to 999999999, it is printed as an Integer.
3) If the absolute value of the number is greater than or
equal to .01 and less than 999999999.2, the number Is
printed in fixed point notation, with no exponent.
4) If the number does not fall under categories 2 or 3,
scientific notation is used.
Scientific notation is used to print real precision numbers, and is
formatted as follows:
SX. XXXXXXXXESTT
where each X is an integer to 9.
The leading S is the sign of the number, nothing for a positive number and a
minus sign ( - ) for a negative number. One non-zero digit is printed
before the decimal point. This Is followed by the decimal point and then
the other eight digits of the mantissa. An E is then printed (for
Exponent), followed by the sign (S) of the exponent; then the two digits
(TT) of the exponent itself. Leading zeroes are never printed; I.e. the
digit before the decimal is never zero. Also, trailing zeroes are never
printed.
If there Is only one digit to print after all trailing zeroes are
suppressed, no decimal point is printed. The exponent sign will be plus ( +
) for positive and minus ( - ) for negative. Two digits of the exponent are
always printed; that is, zeroes are not suppressed in the exponent field.
The value of any number expressed in the form of scientific notation as
described above is the number to the left of the E times 10 raised to the
power of the number to the right of the E.
The following are examples of various numbers and the output format
APPLESOFT will use to print them:
NUMBER OUTPUT FORMAT
+ 1 1
-1 -1
6523 6523
-23.460 -23.46
45.72E5 4572000
l*10'-20 lE+20
-12.34567896*10-10 -1 . 2345679E+1 1
1000000000 lE+09
999999999 999999999
A number typed on the keyboard, or a numeric constant used in an APPLESOFT
program, may have as many digits as desired, up to the maximum length of 38
digits. However, only the first 10 digits are usually significant, and the
tenth digit is rounded off.
For example, if you type
PRINT 1.23456787654321
APPLESOFT responds with
1.23456788
COLOR GRAPHICS EXAMPLE
Type
GR
This will black out the top twenty lines of text on your TV screen and leave
only four lines of text at the bottom. Your APPLE is now in its
low-resolution "color GRaphlcs" mode.
Now type
COLOR = 13
APPLESOFT will only respond with the prompt character:
]
and the flashing cursor, but internally it remembers that you have selected
a yellow color*
Now type
PLOT 20, 20
APPLESOFT will respond by plotting a small yellow square in the center of
the screen. If the square is not yellow, your TV set is not tuned properly:
adjust the tint and color controls to achieve a clear lemon yellow.
Now type
HLIN 0,30 AT 20
APPLESOFT will draw a horizontal line across the leftmost three-quarters of
the screen, one-quarter down from Che top.
Now type
COLOR = 6
to change Co a new color, and then type
VLIN 10,39 AT 30
You will learn more about color GRaphics later. To get back to all text
mode, type
TEXT
The character display on the screen is APPLE'S way of showing color
information as text.
When PRlNTing the answers to problems, it is often desirable to include text
along with the answers, in order to explain the meaning of the numbers.
Type the following:
PRINT "ONE THIRD IS EQUAL TO", 1/3
APPLESOFT will reply with:
ONE THIRD IS EQUAL TO .333333333
PRINT FORMAT
As explained earlier, including a comma ( , ) in a PRINT statement causes it
to space over to the next tab field before the value following the comma is
printed. If we use a semicolon ( ; ) instead of a comma, the next value
will be printed immediately following the previous value. Try it.
Try the following examples:
PRINT 1,2,3
1 2
PRINT l;2;3
123
PRINT -l;2;-3
-12-3
The following is an example of a program that reads a value from the
keyboard and uses that value to calculate and print a result:
10 INPUT R
20 PRINT 3.14159*R*R
RUN
?10
3U.159
Here's what happens. When APPLESOFT encounters the INPUT statement, It
displays a question mark (?) on the screen, and then waits for you to type a
number. When you do (in the above example, 10 was typed), the variable
following INPUT Is assigned the typed value (in this case, the INPUT
variable R was set to 10). Then execution continues with the next statement
in the program, which is line 20 in the above example. When the formula
after the PRINT statement is evaluated, the value 10 is substituted for the
variable R each time R appears in the formula. Therefore, the formula
becomes 3.14159*10*10, or 314.159.
If you haven't already guessed, the program above calculates the area of a
circle with the radius R.
If we wanted to calculate the area of various circles, wg could keep
re-running the program for each successive circle. But there's an easier
way to do it, simply by adding another line to the program, as follows:
30 GOTO 10
RUN
?10
314. 159
?3
28.27431
?4.7
69.3977231
9
BREAK IN 10
]
By putting a GOTO statement on the end of your program, you have caused it
to go back to line 10 after it prints each answer. This could go on
Indefinitely, but we decided to stop after calculating the area for three
circles. Stopping was accomplished by typing a control C (type C while
holding down the CTRL key) and pressing the RETURN key. This caused a
"break" in the program's execution, allowing us to stop. Using control C,
any program can be stopped after executing the current Instruction. Try It
for yourself.
VARIABLE NAMES
The letter R in the program we just ran was termed a "variable." This is
simply a memory location in the computer, identified by the name R. A
variable name must begin witii an alphabetic character and may be followed
by any alphanumeric character. An alphanumeric character is any letter from
A through Z, or any digit from through 9.
A variable name may be up to 238 characters long, but APPLESOFT uses only
the first two characters to distinguish one name from another. Thus,
the names G0OD4NOUGHT and GOLDRUSH refer to the same variable.
In a variable name, any alphanumeric characters after the first two are
ignored unless they contain a "reserved word." Certain words used in
APPLESOFT BASIC commands are "reserved" for their specific purpose. You
cannot use these words as variable names or as part of any variable name.
For instance, FEND would be illegal because END is a reserved word. The
reserved words in APPLESOFT BASIC are listed and discussed in Appendix F.
Variable names ending in $ or % have a special meaning, as discussed later
in this chapter under REAL, INTEGER, AND STRING VARIABLES.
Below are some examples of legal and illegal variable names:
LEGAL ILLEGAL
TP TO (variable names cannot
PSTCS be reserved words)
COUNT RGOTO (variable names cannot contain
Nl% reserved words)
Besides assigning values to a variable with an INPUT statement, you can also
set the value of a variable with a LET or assignment statement.
Try the following examples:
A = 5
PRINT A, A*2
5 10
LET Z = 7
PRINT Z, Z-A
7 2
As can be seen from the examples, the LET is optional In an assignment
statement.
BASIC "remembers" the values that have been assigned to variables using this
type of statement. This "remembering" process uses space in the APPLE'S
memory to store the data.
The values of variables are thrown away and the space in memory used to
store them is released when one of four things occurs:
1) A new line is typed into the program or an old line
is deleted.
2) A CLEAR command is issued.
3) A RUN command Is issued.
4) NEW is typed.
Here is another important fact: until you assign them some other value,
all numeric variables are automatically assigned the value zero. Try this
example:
PRINT Q, Q+2, Q*2
2
Another statement is the REM statement. REM is short for remark. This
statement is used to insert comments or notes into a program. When BASIC
encounters a REM statement the rest of the line is ignored. This serves
mainly as an aid to the programmer, and serves no useful function as far as
the operation of the program in solving a particular problem.
IF . . . THEN
Let's write a program to check whether a typed number is zero or not. With
the statements we've discussed so Ear, this can not be done. What we need
is a statement that provides a conditional branch to another statement. The
IF... THEN statement does just that.
Type NEW, then type this program:
10 INPUT B
20 IF B = THEN GOTO 50
30 PRINT "NON-ZERO"
A0 GOTO 10
50 PRINT "ZERO"
60 GOTO 10
When this program RUN, it will print a question mark and wait for you to
type a value for B. Type any value you wish. The computer will then come
to the IF statement. Between the IF and the THEN portion of the statement,
there is an "assertion." An assertion consists of two expressions separated
by one of the following symbols:
SYMBOL MEAHING
EQUAL TO
> GREATER THAN
< LESS THAN
<> or >< NOT EQUAL TO
<= LESS THAN OR EQUAL TO
>= GREATER THAN OR EQUAL TO
The IF statement is either true or false, depending upon whether the
assertion is true or not. In our present program, for example, if is
typed for B the assertion B=0 is true. Therefore, the IF statement is true,
and program execution continues with the THEN portion of the statement: GOTO
50. Following this command, the computer will skip to line 50. ZERO will
be printed, and then the GOTO statement In line 60 will send the computer
back to line 10.
Suppose a 1 is typed for B. Since the assertion B ~ is now false, the IF
statement Is false and program execution continues with the next line
number, ignoring the THEN portion of the statement and any other statements
in that line. Therefore, NON-ZERO will be printed and the GOTO in line 40
will send the computer back to line 10.
Now try the following program for comparing two numbers (remember to type
NEW first, to delete your last program):
10 INPUT A,B
20 IF A <= B THEN GOTO 50
30 PRINT "A IS LARGER"
40 GOTO 10
50 IF A < B THEN GOTO 80
60 PRINT "THEY ARE THE SAME"
70 GOTO 10
80 PRINT "B IS LARGER"
90 GOTO 10
When this program is RUN, line 10 will print a question mark and wait for
you to type two numbers, separated by a comma. At line 20, if A is greater
than B, A<=B is false and THEN GOTO 50 is ignored. Program execution then
skips to the statement following the next line number, printing A IS LARGER,
and finally line 40 sends the computer back to line 10 to begin again.
At line 20, if A has the same value as B, A<=B is true so THEN GOTO 50 is
executed, sending the computer to line 50. At line 50, since A has the same
value as B, A<B is false. Therefore, THEN GOTO 80 is ignored and the
computer goes on to the following line number, where it is told to print
THEY ARE THE SAME. Finally, line 70 send the computer back to the beginning
again.
At line 20, if A is smaller than B, A<=B is true so program execution
continues with THEN GOTO 50. At line 50, A<B is true so THEN GOTO 80 is
executed. Finally, B IS LARGER is printed and again the computer is sent
back to the beginning.
Try running the last two programs several times. Then try writing your own
program using the IF. . .THEN statement. Actually trying programs of your own
is the quickest and easiest way to understand how APPLESOFT BASIC works.
Remember, to stop these programs just type control C and press RETURN.
ANOTHER COLOR EXAMPLE
Let's try a graphics program. Note the use of REM statements for clarity.
The colon ( : ) is used to separate multiple instructions on one numbered
program line. After you type the program below, LIST it and make sure that
you have typed it correctly. Then RUN it.
100 GR : REM SET COLOR GRAPHICS MODE
110 HOME : REM CLEAR TEXT AREA
120 X = : Y = 5 : REM SET STARTING POSITION
130 XV = 2 : REM SET X VELOCITY
140 YV = 1 : REM SET Y VELOCITY
150 REM CALCULATE NEW POSITION
160 NX = X + XV : NY = Y + YV
170 REM IF BALL EXCEEDS SCREEN EDGE, THEN BOUNCE
180 IF NX > 39 THEN NX = 39 : XV = -XV
190 IF NX < THEN NX = : XV = -XV
200 IF NY > 39 THEN NY = 39 : YV = -YV
210 IF NY < THEN NY = : YV = -YV
220 REM PLOT NEW POSITION IN YELLOW
230 COLOR = 13 : PLOT NX, NY
240 REM ERASE OLD POSITION
250 COLOR = : PLOT X,Y
260 REM SAVE CURRENT POSITION
270 X = NX :Y = NY
280 REM STOP AFTER 250 MOVES
290 I = I + 1 : IF I < 250 THEN GOTO 160
300 PRINT "TO RETURN TO YOUR PROGRAM, TYPE 'TEXT'"
10
The command GR tells the APPLE to switch to its color GRaphics mode. It
also clears the A0 by 40 plotting area to black, sets the text output to a
window of 4 lines of 40 characters each at the bottom of the screen, and
sets the next color to be plotted to black.
HOME is used to clear the text area and set tlie cursor to the top left
corner of the currently defined text window. In color GRaphics mode, this
would be the beginning of text line 20, since text lines through 19 are
now being used for the color graphics plotting area.
The C0LOR= commands in lines 230 and 250 set the next color to be plotted to
the value of the expression following COLOR= .
The PLOT NX, NY command in line 230 plots a small square, in the yellow color
defined by the most recent COLOR= command, at the new position specified by
expressions NX and NY. Remember, NX and NY must each be a number in the
range through 39, or the square will be off the screen and an error
message will result.
Similarly, PLOT X,Y in line 250 plots a small square at the position
specified by expressions X and Y. But X and Y are simply the "old"
co-ordinates NX and NY, saved after plotting the previous yellow square.
Therefore, PLOT X,Y re-plots the "old" yellow square with a square whose
color is defined by COLORE 0. This color is black, the same color as the
background, so the "old" yellow square seems to be erased.
Note; To get from color graphics back to all text mode, type
TEXT
and then press the RETURN key.
Typing TEXT, as instructed, is your escape from GRaphics mode. Ignore the
strange symbols on the screen — they result from converting your graphics
display into text characters. If you don't understand line 290, be patient.
It will be explained in subsequent pages.
As you have seen, the APPLE II can do more than just use numbers. We'll
return to color graphics again, after you have learned more about APPLESOFT
BASIC.
FOR . . . NEXT
One advantage of computers is their ability to perform repetitive tasks.
Suppose we want a table of square roots, for the integers from I to 10.
APPLESOFT BASIC function for square root is SQR ; the form being
SQR(X)
where X is the number whose square root you wish to calculate. We could
write the program as follows:
10 PRINT 1, SQR(l)
20 PRINT 2, SQR(2)
30 PRINT 3, SQR(3)
40 PRINT 4, SQR(A)
50 PRINT 5, SQR(5)
60 PRINT 6, SqR(6)
70 PRINT 7, SQR(7)
80 PRINT 8, SQR(8)
90 PRINT 9, SqR(9)
100 PRINT 10, SQR(10)
This program will do the job; however, it is terribly inefficient. We can
improve the program tremendously by using the IF statement just introduced,
as follows:
10 N = 1
20 PRINT N, SqR(N)
30 N = N + 1
40 IF N <= 10 THEN GOTO 20
When this program is RUN, its output will look exactly like that of the
10-statement program above it. Let's look at how it works.
In line 10, there is a LET statement which sets the variable N to the value
1. At line 20, the computer is told to print N and the square root of N,
using N's current value. Line 20 thus becomes
20 PRINT 1, SQR(l)
and the result of this calculation is printed out.
At line 30, there is what appears at first to be a rather unusual LET
statement. Mathematically, the statement N = N + 1 is nonsense. However,
the important thing to remember is that in a LET statement, the symbol " =
does not signify equality. In this case " = " means "to be replaced with".
The statement simply takes the current value of K and adds 1 to it. Thus,
after the first time through line 30, N becomes 2.
At line 40, since N now equals 2, the assertion N <= 10 is true so the THEN
portion sends the computer back to line 20, with N now at a value of 2.
The overall result is that lines 20 through 40 are repeated, each time
adding 1 to the value N. When N finally equals 10 at line 20, the next line
will increment it to 11. This results in a false assertion at line 40, the
THEN portion is therefore ignored, and since there are no further statements
the program stops.
This technique Is referred to as "looping" or "iteration". Since it is used
quite extensively in programming, there are special BASIC statements for
using It. We can show these with the following program:
10 FOR N = 1 TO 10
20 PRINT N, SqR(N)
30 NEXT N
The output of the program listed above will be exactly the same as the
output of the previous two programs.
12
At line 10, N is set to equal 1. Line 20 causes the value of N and the
square root of N to be printed. At line 30 we see a new type of statement.
The NEXT N statement causes one to be added to N, and then if N <= 11}
program execution goes back to the statement following the FOR. There is
nothing special about the N In this case. Any variable could be used, as
long as it is the same variable name in both the FOR and the NEXT
statements. For instance, ZI could be substituted everywhere there is an N
in the above program and it would function exactly the same.
Suppose we wanted to print a table of square roots for only the even
integers from 10 to 20. The following program would perform this task:
10 N = 10
20 PRINT N, SQR(N)
30 N = N+2
40 IF N <= 20 THEN GOTO 20
Note the similar structure between this program and the one for printing
square roots for the numbers 1 to 10. This program can also be written
using the FOR loop just introduced:
10 FOR N = 10 TO 20 STEP 2
20 PRINT N, SQR(N)
30 NEXT N
Notice that the major difference between this program and the previous one
using FOR loops is the addition of the STEP 2. This tells APPLESOFT to add
2 to N each time, instead of 1 as in the previous program. If no STEP is
given in a FOR statement, APPLESOFT assumes that one is to be added each
time. The STEP can be followed by any expression.
Suppose we wanted Co count backwards from 10 to 1. A program for doing this
would be as follows:
10 1 = 10
20 PRINT 1
30 1 = I-l
40 IF I >= 1 THEN GOTO 20
Notice that we are now checking to see that I is greater than or equal to
the final value. The reason is that we are now counting by a negative
number. In the previous examples it was the opposite, so we were checking
for a variable less than or equal to the final value.
The STEP statement previously shown can also be used with negative numbers
to accomplish this same purpose. This can be done using the same format
used in the other program, as follows:
10 FOR 1 = 10 TO 1 STEP -1
20 PRINT I
30 NEXT 1
13
FOR loops can also be "nested". An example of this procedure follows:
10 FOR I = 1 TO 5
2(2 FOR J = 1 TO 3
30 PRINT I, J
40 NEXT J
50 NEXT I
Notice that the NEXT J comes before the NEXT I. This is because the J-loop
is inside of the I-loop. The following program is incorrect; RUN it and see
what happens.
10 FOR I = 1 TO 5
20 FOR J = 1 TO 3
30 PRINT I, J
40 NEXT I
50 NEXT J
It does not work because when Che NEXT I is encountered, all knowledge of
the J-loop is lost.
ARRAYS
It is often convenient to be able to select any element in a table of
numbers. APPLESOFT allows this to be done through the use of arrays.
An array is a table of numbers. The name of this table, called the array
name, is any legal variable name, A for example. The array name A is
distinct and separate from the simple variable A, and you could use both in
the same program.
To select an element of the table, we give A a subscript: that is, to select
the I'th element, we enclose I in parenthesis (I) and then follow A by this
subscript- Therefore, A(I) is the I'th element in the array A.
NOTE: In this section of the manual we will be concerned with
one-dlmenslonal arrays only; for additional discussion of APPLESOFT commands
relating to arrays, see Chapter 5, "Arrays and Strings."
A(I) is only one element of array A. APPLESOFT must be told how much space
Co allocate for the entire array; that is, what the maximum dimensions of
the array will be. This is done with a DIM statement, using the format
DIM A(15)
In this case, we have reserved space for the array index I to go from to
15. Array subscripts always start at 0; therefore, in the above example we
have allowed for 16 numbers In array A.
If ACI) is used in a program before it has been DlMensioned, APPLESOFT
reserves space for 11 elements (subscripts through 10).
14
As an example of how arrays are used, try the following program, which sorts
a list of 8 numbers typed by you.
90 DIM A(8) : DIMENSION ARRAY WITH MAX. 9 ELEMENTS
1(30 REM ASK FOR 8 NUMBERS
110 FOR I = 1 TO 8
120 PRINT "TYPE A NUMBER: ";
130 INPUT A (I)
140 NEXT I
150 REM PASS THROUGH 8 NUMBERS, TESTING BY PAIRS
160 F = : REM RESET THE ORDER INDICATOR
170 FOR I = 1 TO 7
180 IF A(I) <= A(I+1) THEN GOTO 140
190 REM INTERCHANGE A (I) AND A{I+1)
200 T = A(I)
210 A(I) = A(I+1)
220 A(I+1) = T
230 F = 1 : REM ORDER WAS NOT PERFECT
240 NEXT I
250 REM F = MEANS ORDER IS PERFECT
260 IF F = 1 THEN GOTO 160 : REM TRY AGAIN
270 PRINT : REM SKIP A LINE
280 REM PRINT ORDERED NUMBERS
290 FOR I = 1 TO 8
300 PRINT A (I)
310 NEXT I
When line 90 is executed, APPLESOFT sets aside space for 9 numeric values,
A(0) through A(8). Lines 110 through 140 get the unsorted list from the
user. The sorting itself is done in lines 170 through 240, by going through
the list of numbers and interchanging any two that are not in order. F is
the "perfect order indicator": F = 1 indicates that a switch was done. If
any were done, line 260 tells the computer to go back and check some more.
If a complete pass is made through the eight numbers without interchanging
any (meaning they were all in order), lines 290 through 310 will print out
the sorted list. Note that a subscript can be any expression.
GOSUB . . . RETURN
Another useful pair of statements are GOSUB and RETURN. If your program
performs the same action in several different places, you can use the GOSUB
and RETURN statements to avoid duplicating all the same statements for the
action at each place within the program.
When a GOSUB statement is encountered, APPLESOFT branches to the line whose
number follows GOSUB. However, APPLESOFT remembers where it was in the
program before it branched. When the RETURN statement is encountered,
APPLESOFT goes back to the first statement following the last GOSUB that was
executed. Consider the following program:
15
20 PRINT "WHAT IS THE FIRST NUMBER";
3(8 GOSUB 1(30
40 T = N : REM SAVE INPUT
50 PRINT "VJHAT IS THE SECOND NUMBER";
60 GOSUB 100
70 PRINT "THE SDH OF THE TWO NUMBERS IS "; T + N
80 STOP : REM END OF MAIN PROGRAM
100 INPUT N : REM BEGIN INPUT SUBROUTINE
110 IF N = INT(N) THEN GOTO 140
120 PRINT "SORRY, NUMBER MUST BE AN INTEGER. TRY ACAItl."
130 GOTO 100
140 RETURN : REM END OF SUBROUTINE
This program asks for two numbers which must be Integers, and then prints
the sura of the tvjo. The subroutine in this program is lines 100 through
140. The subroutine asks for a number, and if the number typed in response
is not an Integer, asks for a number again. It will continue to ask until
an Integer value is typed in.
The main program prints VfflAT IS THE FIRST NUMBER, and then calls the
subroutine to get the value of the number N. When the subroutine RETURNS
(to line 40), the number that was typed (N ) is saved In the variable T.
This is done so that when the subroutine is called a second time, the value
of the first number will not be lost.
IflrlAT IS THE SECOND NUMBER is then printed, and the subroutine is again
called, this time to get the second number.
When the subroutine RETURNS the second time (to line 70), THE SUM OF THE TWO
NUMBERS IS is printed, followed by the value of their sum, T contains the
value of the first number that was typed, and N contains the value of the
second number.
The next statement in the program is a STOP statement. This causes the
program to stop execution at line 80. If the STOP statement were not
included at this point, program execution would "fall into" the subroutine
at line 100. This is undesirable because we would be asked to type still
another number. If we did, the subroutine would try to RETURN; and since
there was no GOSUB which called the subroutine, an error would occur. Each
GOSUB in a program should have a matching RETURN executed later, and a
RETURN should be encountered only if it is part of a subroutine which has
been called by a GOSUB.
Either STOP or END can be used to separate a program from its subroutines.
STOP will print a message saying at what line the STOP was encountered; END
will terminate the program without any message. Both commands return
control to the user, printing the APPLESOFT prompt character j and a
flashing cursor.
16
READ . . . DATA . . . RESTORE
Suppose you want your program to use numbers that don't change each time the
program is run, but which are easy Co change if necessary. BASIC contains
special statements for this purpose, called the READ and DATA statements.
Consider the following program:
m PRINT "GUESS A NUMBER";
20 INPUT G
iff READ D
40 IF D = -999999 THEN GOTO 90
50 IF D <> G THEN GOTO 30
60 PRINT "YOU ARE CORRECT"
70 END
90 PRINT "BAD GUESS, TRY AGAIN."
95 RESTORE
100 GOTO 10
110 DATA 1,393,-39,28,391,-8,0,3.14,90
120 DATA 89,5,10,15,-34,-999999
This is what happens when the program is RUN: when the READ statement is
encountered, the effect is the same as an INPUT statement, but instead of
getting a number from the keyboard, a number is read from the DATA
statements.
The first time a number is needed for a READ, the first number in the first
DATA statement is returned. The second time one is needed, the second
number in the first DATA statement is returned. When the entire contents
of the first DATA statement have been read in this manner, the second DATA
statement will then be used. DATA is always read sequentially in this
manner, and there may be any number of DATA statements in your program.
The purpose of this program is to play a little game in which you try to
guess one of the numbers contained in the DATA statements. For each guess
that is typed in, the computer reads through all of the numbers in the DATA
statements until it finds one that matches the guess. If READ returns
-999999, all of the available DATA numbers have been used, and a new guess
must be made.
Before going back to line 10 for another guess, we need to make the READ
begin with the first piece of data again. This is the function of the
RESTORE. After RESTORE is encountered, the next piece of data READ will
again be the first item in the first DATA statement.
DATA statements may be placed anywhere within the program. Only READ
statements make use of the DATA statements in a program, and any other time
they are encountered during program execution they will be ignored.
17
REAL, INTEGER AND STRING VARIABLES
There are three different types of variables used in APPLESOFT BASIC. So
far we have just used one type — real precision. Numbers in this mode are
displayed with up to nine decimal digits of accuracy and may range up to
approximately 10 to the 38th power. APPLESOFT converts your numbers from
decimal to binary for its internal use and then back Co decimal when you ask
it to PRINT the answer. Because of rounding errors and other
unpredictables , internal raath routines such as square root, divide, and
exponent do not always give the exact number that you expected.
The number of places to the right of the decimal point may be set by
rounding off the value prior to PRINTing it. The general formula for
accomplishing this is:
X = INT(X*10~D+. 5)/INT(10~D+.5)
In this case, D is the number of decimal places. A faster way to set the
number of decimal places is to let P=10T) and use the formula:
X = lNT(X*P+.5)/P
where P=I0 is one place, P=100 is 2 places, P=1000 is 3 places, etc. The
above works for X>=1 and X<999999999. A routine to limit the number of
digits after the decimal point is given in the next section in this chapter.
The table below summarizes the three types of variables used in APPLESOFT
BASIC programming:
Description
Strings
(0 to 255 characters)
integers (must be In range
of -32767 to +32767)
Real Precision
(Exponent -38 to +38,
with 9 decimal digits)
An integer or string variable must be followed by a % or $ at each use of
that variable. For example, X, X% and X$ are different variables.
Integer variables are not allowed in FOR or DBF statements. The greatest
advantage of integer variables Is their use in array operations wherever
possible, to save storage space.
All arithmetic operations are done in real precision. Integers and integer
variable values are converted to real precision before they are used in a
calculation. The functions SIN, COS, ATN, TAN, SQR, LOG, EXP and RND also
convert their arguments to real precision and give their results as such.
When a number is converted to an integer. It is truncated (rounded down).
For example:
I%=.999 A7.=-.01
PRINT 1% PRINT A%
-1
18
Symbol to
Append
Example
to Variable Name
$
A$
ALPHA$
%
cu
none
C
BOY
If you assign a real number to an integer variable, and then PRINT the value
of the integer variable, it Is as if the INT function had been applied. No
automatic conversion is done between strings and numbers: assigning a
number to a string variable, for instance, results in an error message.
However, there are special functions for converting one type to the other.
STRINGS
A sequence of characters is referred to as a "literal". A "string" Is a
literal enclosed in quotation marks. These are all strings:
"BILL"
"APPLE"
"THIS IS A TEST"
Like numeric variables, string variables can be assigned specific values.
String variables are distinguished from numeric variables by a $ after the
variable name.
For example, try the following:
AS = "GOOD HORNING"
PRINT AS
GOOD MORNING
In this example, we set the string variable AS to the string value "GOOD
MORNING".
Now that we have set AS to a string value, we can find out what the length
of this value is (the number of characters it contains). We do this as
follows :
PRINT LEN(AS), LEN("YES")
12 3
The LEN function returns an integer equal to the number of characters in a
string: its LENgth.
The number of characters in a string expression may range from to 255. A
string which contains characters is called a "null" string. Before a
string variable is set to a value in the program, It is initialized to the
null string. PRINTing a null string on the terminal will cause no
characters to be printed, and the cursor will not be advanced to the next
column. Try the following:
PRINT LEN(qS); QS; 3
03
Another way to create the null string is to use
Q$ = ""
or the equivalent statement
LET QS = ""
Setting a string variable to the null string can be used to free up the
string space used by a non-null string variable. But you can get into
trouble assigning the null string to a string variable, as discussed in
Chapter 7 under the IF statement.
19
Often It Is desirable to retrieve part of a string and manipulate it. Now
that we have set A$ to "GOOD MORNING", we might want to print out only the
first four characters of A$.
We would do so like this:
PRINT LEFTS (A$, 4)
GOOD
LEFT$(AS,N) is a string function which returns a substring composed of the
leftmost N characters of its string argument, AS in this case. Here's
another example:
FOR N = 1 TO LEN(AS) : PRINT LEFT$(AS,N) : NEXT N
G
GO
GOO
GOOD
GOOD
GOOD M
GOOD HO
GOOD MOR
GOOD MORN
GOOD MORN I
GOOD MORN IN
GOOD MORNING
Since AS has 12 characters, this loop will be executed with N=l, 2, 3,...,
11, 12. The first time through, only the first character will be printed;
the second time the first two characters will be printed, etc.
There is another string function called RIGHTS. RIGHTS (AS, N) returns the
rightmost N characters from the string expression A$. Try substituting
RIGHTS for LEFTS In the previous example and see what happens.
There is also a string function which allows us to take characters from the
middle of a string. Try the following:
FOR N = 1 TO LEN(AS) : PRINT MIDS(A$,N) : NEXT N
MIDS(A$,N) returns a substring starting at the Nth position of AS to the end
(last character) of AS. The first position of the string is position 1 and
the last possible position of a string is position 255.
Very often, it is desirable to extract only the Nth character from a string.
This can be done by calling MIDS with three arguments: MID$ (AS,N, 1 ) . The
third argument specifies the number of characters to be returned,
beginning with character N.
20
For example:
FOR N = l TO LEN(AS):PRINT MID$ (AS,N, 1 ) , MID$ (A$,N, 2 ) : NEXT N
G GO
00
OD
D D
M
M MO
OR
K RN
13 HI
1 IN
N NG
G G
See Chapter 5 for more details on the workings of LEFT?, RIGHT? and MID$.
Strings may also be concatenated (put or joined together) through the use of
the plus ( + ) operator. Try the following:
B5 = A$ + " " + "BILL"
PRINT B$
GOOD MORNING BILL
Concatenation is especially useful if you wish to take a string apart and
then put it back together with slight raodif ications . For Instance:
C$ = RIGHT?(BS,3) + "-" + LEFT$(B$,4) + "-" + MID$(B$,6,7)
PRINT C$
BILL -GOOD-MORNING
Sometimes it is desirable to convert a number to its string representation
and vice-versa. The functions VAL and STR§ perform these tasks. Try the
following:
STRINGS = "567.8"
PRINT VAL (STRING?)
567.8
STRING? = STRS(3. U15)
PRINT STRING?, LEFT$(STRING$, 5 )
3.1415 3.141
The SIR? function can be used to change numbers to a certain format for
Input or output. You can convert a number to a string and then use LEFT?,
RIGHT?, MID? and concatenation to reformat the number as desired.
21
The following short program demonstrates how string functions may be used to
format numeric output;
00 INPUT "TYPE ANY NUMBER: "; X
10 PRINT : REM SKIP A LINE
20 PRINT "AFTER CONVERSION TO REAL PRECISION,"
30 INPUT "HOW MANY DIGITS TO RIGHT OF DECIMAL? "; D
40 GOSUB 1000
50 PRINT "***" : REM SEPARATOR
60 GOTO 100
000 X$ = STR$(X) : REM CONVERT INPUT TO STRING
010 REM FIND POSITION OF E, IF IT EXISTS
020 FOR I = 1 to LEN(X$)
030 IF MID$(XS,I,1) <> "E" THEN NEXT I
040 REM I IS NOW AT EXPONENT PORTION (OR END)
050 REM FIND POSITION OF DECIMAL, IF IT EXISTS
060 FOR J = 1 TO I-l
070 IF M1D$(X$,J,1) <> "." THEN NEXT J
080 REM J IS NOW AT DECIMAL (OR END OF NUMBER PORTION)
090 REM DO D DIGITS EXIST TO RIGHT OF DECIMAL?
100 IF J+D <= I-l THEN N = J+D : GOTO 1130 : REM YES
110 N = I-l : REJl NO, SO PRINT ALL DIGITS
120 REM PRINT NUMBER PORTION AND EXPONENT PORTION
130 PRINT LEFT$(XS,N) + MID$(X$,1)
140 RETURN
The above program uses a subroutine starting at line 1000 to print out a
predefined real variable X truncated, not rounded off, to D digits after the
decimal point. The variables X$, I and J are used In the subroutine as
local variables.
Line 1000 converts the real variable X to string variable X$.
Lines 1020 and 1030 scan the string to see if an E is present. I is set to
the position of the E, or to LEN(X$) + 1 if no E is there. Lines 1060 and
1070 search the string for a decimal point. J is set to the position of the
decimal point, or to I-l if there is no decimal.
Line 1100 tests whether there exist at least D digits to the right of the
decimal. If they do exist, the number portion of the string must be
truncated to length J+D, which is D positions to the right of J, the decimal
position. The variable N is set to this length.
If there are fewer than D digits to the right of the decimal, the entire
number portion may be used. Line 1110 sets the variable N to this length
(I-l).
Finally, line 1130 prints out variable X as the concatenation of two
sub-strings. LEFT$(X$,N) returns the significant digits of the number
portion, and MID$(XS,I) returns the exponent portion, if it was there.
STRS can also be used to conveniently find out how many print-positions a
number will take. For example:
PRINT LEN(STRS(33333. 157))
9
22
If you have an application where a user is typing a question such as
WHAT IS THE VOLUME OF A CYLINDER OF RADIUS 5.36 FEET
AND HEIGHT 5. 1 FEET?
you can use the VAL function to extract the numeric values 3.36 and 5.1 from
the question. Additional information on these functions and CHR$ and ASC is
In Chapter 5.
The following program sorts a list of string data and prints out the
alphabetized list. This program is very similar to the one given earlier
for sorting a numeric list.
IW DIM A$CI3)
U0 FOR I = 1 TO 15 : READ A$(l) : NEXT I
120 F = : 1=1
130 IF A$(I) <= AS(I+1) THEN GOTO 180
140 T$ = A$(I + 1)
150 A5(I+1) = AS(I)
160 AS(I) = TS
170 F=l
180 I = I+l : IF I <= 15 THEN GOTO 130
190 IF F = 1 THEN GOTO 120
200 FOR I = 1 TO 15 : PRINT A$(I) : NEXT I
220 DATA APPLE, DOG, CAT, RANDOM, COMPUTER, BASIC
230 DATA MONDAY, "***ANSWER***","F0O: "
2A0 DATA COMPUTER, FOO.ELP, MILWAUKEE, SEATTLE, ALBUQUERQUE
MORE COLOR GRAPHICS
In two previous examples, we've explained how the APPLE II can do color
graphics as well as text. In GRaphics mode, the APPLE displays up to 1600
small squares, in any of 16 possible colors, on a 40 by 40 grid. It also
provides 4 lines of text at the bottom of the screen. The horizontal or
x-axis is standard, with the leftmost position and 39 the rightmost. The
vertical or y-axis is non - standard in that It is inverted: is the
top most position and 39 is the bottomm ost.
23
10 GR : REM INITIALIZE COLOR GRAPHICS;
SET 40X40 TO BLACK.
SET TEXT WINDOW TO 4 LINES AT BOTTOM
20 HOME : REM CLEAR ALL TEXT AT BOTTOM
30 COLOR = 1 : PLOT 0,0 : REM MAGENTA SQUARE AT 0,0
40 LIST 30 : GOSUB 1000
50 COLOR = 2 : PLOT 39,0 ; REM BLUE SQUARE AT X=39,Y=0
60 HOME : LIST 50: GOSUB 1000
70 COLOR = 12 : PLOT 0,39 : REM GREEN SQUARE AT X=0,Y=39
80 HOME : LIST 70 : GOSUB 1000
90 COLOR = 9 : PLOT 39,39: REM ORANGE SQUARE AT X=39,Y=39
100 HOME : LIST 90 : GOSUB 1000
110 COLOR = 13: PLOT 19,19: REM YELLOW SQUARE AT CENTER
OF SCREEN
120 HOME : LIST 110 : GOSUB 1000
130 HOME : PRINT "PLOT YOUR OWN POINTS"
140 PRINT "REMEMBER, X & Y MUST BE >=0 i <=39"
150 INPUT "ENTER X,Y: "; X,Y
160 COLOR = 8 : PLOT X,Y : REM BROWN SQUARES
170 PRINT "TYPE 'CTRL C AND PRESS RETURN TO STOP"
180 GOTO 150
1000 PRINT "***HIT ANY KEY TO CONTINUE***";: GET A$: RETURN
After you have typed the program, LIST it and check for typing errors. You
may want to SAVE it on cassette tape for future use. Then RUN the program.
The command GR tells APPLE to switch to its color GRaphics mode.
The COLOR command sets the next color to be plotted. That color remains set
until changed by a new COLOR command. For example, the color plotted in
line 160 remains the same no matter how many points are plotted. The value
of the expression following COLOR must be in the range to 255 or an error
may occur. However, there are only 16 different colors, usually numbered
from through 15.
Change the program by re-typing lines 150 and 160 as follows:
150 INPUT "ENTER X, Y, COLOR: "; X, Y, Z
160 COLOR = Z: PLOT X,Y
Now RUN the program and you will be able to select your own colors as well
as points. We will demonstrate the APPLE'S color range in a moment.
The PLOT X,Y command plots a small square of color defined by the last COLOR
command at the position specified by expressions X and Y. Remember, X and Y
must each be a number in the range through 39.
The GET instruction in line 1000 is similar to an INPUT instruction. It
waits for a single character to be typed on the keyboard, and assigns that
character to the variable following GET. It is not necessary to press the
RETURN key. In line 1000, GET A$ is just used to stop the program until any
key is pressed.
Remember: To get from color graphics back to all text mode, type
TEXT
and then press the RETURN key. The APPLESOFT prompt character will then
reappear.
24
Type the following program and RUN it to display the APPLE'S range of colors
(remember to type NEW first).
10 GR : HOME
20 FOR 1 = TO 31
30 COLOR =1/2
40 VLIN 0,39 AT 1
50 NEXT 1
60 FOR I = TO lA STEP 2 : PRINT TAB (1*2 +1); 1; : NEXT I
70 PRINT
80 FOR I = 1 TO 15 STEP 2 : PRINT TAB(I*2 +1); I; : NEXT I
90 PRINT : PRINT "STANDARD APPLE COLOR BARS";
Color bars are displayed at double their normal width. The leftmost bar is
black as set by COLOR=0; the rightmost, white, is set by C0L0R=15.
Depending on the tint setting on your TV, the second bar as set by COLOR^l
will be magenta (reddish-purple) and the third (COL0R=2) will be dark blue.
Adjust your TV tint control for these colors. In Europe, color tints may be
different.
In the last program a command of the form VLIN Yl, Y2 AT X was used in line
40. This command plots a vertical line from the y-coordinate specified by
expression Yl to the y-coordinate specified by expression Y2, at the
horizontal position specified by expression X. Yl, Y2 and X must evaluate
to values in the range through 39. Y2 may be greater than, equal to, or
smaller than Yl. The command HLIN XI, X2 AT Y is similar to VLIN except
that it plots a horizontal line.
Note: The APPLE draws an entire line just as easily
as It plots a single point]
HIGH-RESOLUTION COLOR GRAPHICS
Now that you are familiar with the APPLE'S low-resolution graphics, you will
find that understanding high-resolution graphics is easy. The commands have
a similar appearance: usually they are formed by just adding an H (for High
resolution) to the ones you already know. For instance, the command
HGR
sets high-resolution graphics mode, clears the high-resolution screen to
black, and leaves 4 lines for text at the bottom of the screen. In this
mode, you are plotting points on a grid that is 280 x-positions wide by 160
y-positions high. This lets you draw on the screen with much more detail
than the 40 by 40 grid of low-resolution graphics. Typing TEXT returns you
to the normal text mode.
In addition to the HGR screen, there is also a second high-resolution
screen you can use if your APPLE contains at least 24K bytes of memory.
High-resolution graphics mode for the "second page" of memory is invoked by
the command
HGR 2
This clears the entire screen to black, giving you a plotting surface that
is 280 x-posltions across by 192 y-positlons high, and no text at the
bottom. Again, type TEXT to see your program.
25
Sound wonderful? It is; but you do have to make some sacrifice for this
new ability: there are fewer colors. The color for high-resolution graphics
is set by a command of the form
HCOLOR = N
where N is a number from (black) to 7 (white). See Chapter 8 for a
complete list of the colors available. Because of the construction of color
televisions, these colors vary from TV to TV and from one plotted line to
the next.
Finally, there is one easy instruction for all plotting in high-resolution
graphics. To see this in action, type
HCOLOR = 3
HGR
HPLOT 130, IW
The last command plots a high-resolution dot in the color you set with
HCOLOR (white) at the point x=13(}, y=l(il0. As in low-resolution graphics,
x=0 is at the left edge of the screen. Increasing to the right; y=0 is at
the top of the screen, increasing downward . Maximum value for x is 2 79;
maximum y is 191 (but in HGR's mixed graphics-plus-text mode, y values are
only visible down to y=159).
Now type
HPLOT 20, 15 TO 145,80
Like magic, a white line is drawn from the point x=20, y=15 to the point
x=145, y=80. HPLOT can draw lines between any two points on the screen —
horizontal, vertical, or any angle. Do you want to connect another line to
the end of the previous one? Type
HPLOT TO 12,80
This form of the command takes its starting point from the last point
previously plotted , and also takes its color from that point (even If
you have Issued a new HCOLOR command since that point was plotted). You can
even "chain" these commands in one instruction. Try this:
HPLOT 0,0 TO 279,0 TO 279,159 TO 0,159 TO 0,0
You should now have a white border around all four sides of the screen!
Here's a program that draws pretty "moire" patterns on your screen:
80 HOME : REM CLEAR THE TEXT AREA
100 VTAB 24 : REM MOVE CURSOR TO BOTTOM LINE
120 HGR : REM SET HIGH -RESOLUTION GRAPHICS MODE
140 A = RND(l) * 279 : REM PICK AN X FOR "CENTER"
160 B = RND(l) * 159 : REM PICK A Y FOR "CENTER"
180 1% = (RND(l) * 4) + 2 : REM PICK A STEP SIZE
200 HTAB 15 : PRINT "STEPPING BY "; 1%;
220 FOR X = TO 278 STEP 1% : REM STEP THRU X VALUES
240 FOR S = TO 1 : REM 2 LINES, FROM X AND X+1
260 HCOLOR = 3 * S : REM FIRST LINE BLACK, NEXT WHITE
280 REM DRAW LINE THROUGH "CENTER" TO OPPOSITE SIDE
300 HPLOT X+S,0 TO A,B TO 279-X-S,159
320 NEXT S, X
26
340 FOR Y = 3 TO 158 STEP IZ : REM STEP THRU Y VALUES
36(3 FOR S = TO 1 : REM 2 LINES, FROM Y AND Y+1
380 HCOLOR = 3 * S : REM FIRST LIKE BLACK, NEXT WHITE
400 REM DRAW LINE THROUGH "CENTER" TO OPPOSITE SIDE
420 HPLOT 279, Y+S TO A,B TO 0, 159-Y-S
440 NEXT S, Y
460 FOR PAUSE = 1 TO 1500 : NEXT PAUSE : REM DELAY
480 GOTO 120 : REM DRAW A NEW PATTERN
This is a rather long program; type it in carefully and LIST it in portions
(LIST 0,320 for instance) to check your typing. We've added a space betvreen
some lines to make the program easier to read. Your LISTing will not show
those spaces. When you are sure it is correct, RUN the program.
VTAB and HTAB are cursor-moving commands, used to print a character at a
pre-determined position on the text screen. VTAB 1 places the cursor in the
top line; VTAB 24 places it in the bottom line. HTAB 1 puts the cursor In
the leftmost position on the current line; HTAB 40 puts it in the rightmost
position. In a PRINT instruction like the one at line 200, you may need a
final semicolon to avoid a subsequent "line feed" that displaces your
message.
The function RND (N ) , where N is any positive number, returns a random number
in the range from to .999999999 (see Chapter 10 for a complete discussion
of RND). Thus line 180 assigns to Che integer variable 1% a random number
from 2 to 5 (a number is always rounded down when it is converted to an
integer). The STEP size in a FOR... NEXT loop does not have to be an
integer, but it may be easier to predict the results for an integer STEP.
As you saw in lines 320 and 440, one instruction can provide the NEXT for
more than one FOR statement. Be careful that you list the NEXT variables in
the right order, though, to avoid crossed loops.
Line 460 is Just a "delay loop" that gives you a moment to admire one
pattern before the next one begins. Each time line 480 sends the computer
back to the HGR command in line 120, HGR clears the screen for the next
pattern.
To go back to programming, stop the pattern by typing
Ctrl C
and then type
TEXT
Can you think of ways to change the program? After SAVEing this version on
your cassette recorder or disk, try making the value of HCOLOR change
randomly. Try drawing first white, then black lines, or only white lines.
HAPPY PROGRAMMING!
27
CHAPTER
DEFINITIONS
30 Syntactic Definitions and Abbreviations
36 Rules for Evaluating Expressions
36 Conversion of Types
36 Execution Modes
SYNTACTIC DEFINITIONS AND ABBREVIATIONS
{For an alphabetic list of these definitions, see Appendix N)
The following definitions use metasymbols such as { and \ — characters
used to unambiguously indicate structures or relationships in APPLESOFT.
The metasyrabols are not part of APPLESOFT. In addition to the true
metasymbols, the special symbol := Indicates the beginning of a complete or
partial definition of the terra that is to the left of :=
1 := metasymbol used to separate alternatives
(note: an item may also be defined separately
for each alternative)
[ ] := metasymbols used to enclose material which
is optional
{ } := metasymbols used to enclose material which
may be repeated
\ := metasymbol used to enclose material whose
value is to be used: the value of x
is written \x\
:= metasymbol which indicates a required space
metasymbol
lower-case letter
:=a|b|c|d|e|f|g|h|i|j|k|l|in|n|o|p|q|r|s|t|u|v|w|x|y|z
metasymbol
:= lower-case letter
digit
:= 1|2|3|4|5|6|7|8|9|0
metaname
:= {metasymbol} [digit]
metasymbol
; = a single digit concatenated to a metaname
special symbol used by APPLESOFT II
:= special
special
:= !|#I$I%I&I'I(I)I*|:|=|-I@l + I;l?l/I>|.|<l,lin"
Control characters (characters which are typed
while holding down the CTRL key) and the null
character are also specials. APPLESOFT uses the
right bracket ( ] ) only for the prompt character;
in this document it is used as a metasymbol.
letter
:=A|B|C|D|E|F|G|H|I|J|K|L|M|N|0|P|Q|R|S|T|U|V|W|X|Y|Z
character
:= letter Idigit I special
alphanumeric character
:= letterldigit
30
:= letter [{letter Idigit}]
A name may be up to 238 characters in length.
When distinguishing one name from another, APPLESOFT
Ignores any alphanumeric characters after the first
two. APPLESOFT does not distinguish between the
names G00D4LITTLE and GOLDRUSH. However, even the
ignored portion of a name must not contain a
special, a quote (") or any of APPLESOFT'S
"reserved words." (See the Appendix A for a list of
these reserved words and comments on exceptions to
this rule. )
integer
:= [+|-]{digit}
Integers must be in the range -32767 to 32767.
When converting non-integers into Integers,
APPLESOFT may usually be considered to truncate
the non-integer to the next smaller integer.
However, this is not quite true in the limit as
the non-integer approaches the next larger integer.
For instance:
A%=123.999 999 959 999 B%=123.999 999 96
PRINT A% PRINT A%
123 124
C%=12345.999 995 999 D%=12345.999 996
PRINT C% PRINT D%
12345 12346
(Spaces added for easier reading)
An array integer occupies 2 bytes (16 bits) in memory.
integer variable name
; = narae%
A real may be stored as an integer variable, but
APPLESOFT first converts the real to an integer.
real
[+ I -] {digit} [.{digit}] [E[+|-]digit [digit)]
[+ I -] [{digit}] . [{digit}] [E[+|-]digit [digit]]
The letter E, as used in real number notation
(a form of "scientific notation"),
stands for "exponent." It is shorthand
for *10" Ten is raised to the power of the
number on E's right, and the number on E's
left is multiplied by the result.
In APPLESOFT, reals must be In the range -1E38
to 1E38 or you risk the 70VERFLOW ERROR message.
Using addition or subtraction, you may be able
to generate numbers as large as 1.7E38 without
receiving this message.
31
A real whose absolute value is less than about
2.9388E-39 will be converted by APPLESOFT to zero.
APPLESOFT recognizes the following as reals when
presented by themselves, and evaluates them as zero:
+. -. .E +.E -.E
.E+ -E- +.E- +.E+ -.E+ -.E-
Therefore, the array element M(.) is the same as M(0)
In addition to the abbreviated reals listed above,
the following are recognized as reals and evaluated
as zero when used as numeric responses to INPUT or
as numeric elements of DATA:
+ - E +E -E space
E+ E- +E+ +E- -E+ -E-
The GET instruction evaluates all of the single-
character reals in the above lists as zero.
When printing a real number, APPLESOFT will show
at most nine digits (see exception, below),
excluding the exponent (if any). Any further
digits are rounded off. To the left of the decimal
point, any zeros preceding the leftmost non-zero
digit are not printed. To the right of the decimal
point, any zeros following the rightmost non-zero
digit are not printed. If there are no non-zero
digits to the right of the decimal point, the
decimal point is not printed.
^
Rounding can be curious:
PRINT 99 999 999.9
99 999 999.9
PRINT 99 999 999.9(3
1(20 0W (300
PRINT 11.111 111 450 00
11.111 ill 5
PRINT 11.111 HI 451 9
11.111 111 4
(Spaces added for easier reading)
If a real's absolute value is greater than or
equal to .01 and less than 999 999 999.2, the
real Is printed in fixed-point notation.
That is, no exponent is displayed. In the range
32
.0 100 000 000 5 to .0 999 999 999
reals are printed with up to ten digits, including
the zero immediately to the right of the decimal
point. This is the only exception to the limit of
nine printed digits, excluding the exponent.
If you attempt to use a number with more than 38
digits, such as
211. llUlllllllUllllllUUllUllUlllll
then the message
'.'OVERFLOW ERROR
is printed, even if the number is clearly within
the range -1E38 through IE38. This is true even
if most of the digits are trailing zeroes, as in
211.00000000000^106(0000000000000000000000
Leading zeros, however, are Ignored. If the first
digit is a one, and the second digit is less than
or equal to six, numbers with 39 digits may be
used without getting an error message.
A real occupies 5 bytes (40 bits) in memory.
real variable name
: = name
arithmetic variable
: = avar
avar
: = name I name%
All simple variables occupy 7 bytes in memory, 2 bytes for
the name and 5 bytes for the real or integer value.
delimiter
:= ^l(l)l=|-| + ri>l<l/l*l,l;|:
A name does not have Co be separated froin a
preceding or following reserved word by any
of these delimiters.
arithmetic operator
: = aop
aop
;= +i-i*i/r
arithmetic logical operator
:= alop
alop
:= AND |0R | = |>|<|<> I X !>=!=> !<=!=<
NOT is not included here on purpose.
operator
:= op
: = aop [alop
33
arithmetic expression
:= aexpr
aexpr
:= avar I real I integer
:= (aexpr)
If parentheses are nested more than 36 levels deep, the
?OUT OF MEMORY ERROR occurs.
:= [+l-|NOT]aexpr
Unary NOT appears here, along with unary + and -.
:= aexpr op aexpr
subscript
;= (aexpr [{, aexpr}])
The maximum number of dimensions is 89,
although in practice this will be limited by
Che extent o£ memory available, .aexpr must be
positive, and in use it is converted to an integer.
avar
aexpr
:= avar subscript
:= avar subscript
literal
:= [{character}]
string
:= "[{character})"
A string occupies 1 byte (8 bits) for its length, 2 bytes for its
location pointer, and 1 byte for each character in the string.
:= "[{character}] return
This form of the string can appear only at the end of a line.
null string
, _ lilt
string variable name
; = name?
string variable
; = svar
svar
:= name$|narae5 subscript
The location pointer and variable name each occupy 2 bytes
in memory. The length and each string character occupy one byte.
string operator
: = sop
sop
string expression
:= sexpr
34
sexpr
:= Buar [string
:= sexpr sop sexpr
string logical operator
:= slop
slop
:= =|>|>=|=>|<|<=|=<|<>|><
aexpr
:= sexpr slop sexpr
variable
: = var
var
:= avarlsvar
expression
: = expr
expr
: = aexpr | sexpr
prompt character
:= J
The right bracket (]) Is displayed when APPLESOFT
is ready to accept another command.
reset
:= a press of the key marked "RESET"
esc
:= a press of the key marked "ESC"
return
=: a press of the key marked "RETURN"
Ctrl
:= hold down the key marked "CTRL" while the following
named key is pressed.
line number
: = linenum
1 inenuni
:= {digit}
Line numbers must be in the range to 63999
or a ? SYNTAX ERROR message results.
line
:= linenum [{instruction: }J instruction return
A line may have up to 239 characters. This
includes all spaces typed by the user, but
does not include spaces added by APPLESOFT
in formatting the line.
35
RULES FOR EVALUATING EXPRESSIONS
Operators are listed vertically in order of execution, from the highest
priority (parentheses) to the lowest priority (OR), Operators listed on the
same line are of the same priority. Operators of the same priority in an
expression are executed from left to right.
( )
+ - NOT unary operators
* /
+ -
><>=<= => =< <> X =
AND
cm
CONVERSION OF TYPES
when an integer and a real are both present in a calculation, all numbers
are converted to reals before the calculation takes place. The results are
converted to the arithmetic type (integer or real) of the final variable to
which they are assigned. Functions which are defined on a given arithmetic
type will convert arguments of another type to the type for which they are
defined. Strings and arithmetic types cannot be mixed. Each can be
converted to the other by functions provided for the purpose.
EXECUTION MODES
imm Some instructions may be used in immediate-execution mode
(imm) in APPLESOFT. In immediate-execution mode, an
instruction must be typed without a line number. When the
RETURN key is pressed, the instruction is immediately executed.
def Instructions used in deferred-execution mode (def) must
appear in a line that begins with a line number. When the
RETURN key is pressed, APPLESOFT stores the numbered line
for later use. Instructions in deferred-execution mode
are executed only when their line of a program is RUN.
36
CHAPTER
SYSTEM AND
UTILITY COMMANDS
38 LOAD and SAVE
38 NEW
38 RUN
39 STOP, END, Ctrl C, reset and CONT
40 TRACE and NOTRACE
40 PEEK
4 1 POKE
41 WAIT
43 CALL
43 HIMEM:
44 LOMEM:
45 USR
LOAD imm & def
SAVE 1mm & def
LOAD
SAVE
These LOAD a program from a cassette tape and SAVE a program on a cassette
tape, respectively. There is no prompting message or other signal issued by
these commands; the user must have the cassette tape recorder running in the
proper mode (play or record) when the command is executed. LOAD and SAVE do
not verify that the recorder Is in the proper mode or even that the recorder
is present. Both commands sound a "beep" to signal the beginning and the
end of recordings.
Program execution continues after a SAVE operation, but a LOAD deletes the
current program when it begins reading new information from the cassette
tape.
Only reset can interrupt a LOAD or a SAVE.
If the reserved word LOAD or SAVE is used as the first characters of a
variable name, the reserved-word command may be executed before any
7SYNTAX ERROR message is given. The statement
SAVERING = 5
causes APPLESOFT to try SAVEing the current program. You can wait for the
second "beep" (and the 7SYNTAX ERROR message) or press reset.
The statement
LOADTOJOY =47
hangs the system, while APPLESOFT deletes the current program and waits
indefinitely for a program from the cassette recorder. Only by pressing
reset can you regain control of the computer.
NEW inm i def
NEW
No parameters. Deletes current program and all variables.
RUN imm & def
RUN [linenum]
Clears all variables, pointers, and stacks and begins execution at the line
number indicated by linenum. If linenum is not indicated, RUN begins at the
lowest numbered line in the program, or returns control to the user if there
is no program in memory.
In deferred execution mode, if linenum is given but there is no such line in
the program, or if linenum is negative, then the message
?UNDEF'D STATEMENT ERROR
38
appears* If linenum is greater than 63999, the message
? SYNTAX ERROR
appears. You are not told in which line the error occurred.
In immediate execution mode, on the other hand, these two messages become
?UNDEF'D STATEMENT ERROR IN xxxx
and
7SYNTAX ERROR IN xxxx
where xxxx can be various line numbers, usually above 65000.
If RUN is used in an immediate-execution program, any subsequent portion of
the immediate-execution program is not executed.
STOP iirm 6. def
END iram 4 def
Ctrl C iram only
reset Imci only
CONT imm & def
STOP
END
Ctrl C
reset
CONT
STOP causes a program to cease execution, and returns control of the
computer to the user. It prints the message
BREAK IN linenum
where linenum is the line number of the statement which executed the STOP.
END causes a program to cease execution, and returns control to the user.
No message is printed.
Ctrl C has an effect equivalent to the insertion of a STOP statement
immediately after the statement that is currently being executed. Ctrl C
can be used to interrupt a LISTing. It can also be used to interrupt an
INPUT, but only If it is the first character entered. The INPUT is not
Interrupted until return is pressed.
reset stops any APPLESOFT program or command unconditionally and
immediately. The program is not lost, but some program pointers and stacks
are cleared. This command leaves you in the system monitor program, as
indicated by the monitor's prompt character ( * ). To return to APPLESOFT
without destroying the current stored program, type Ctrl C return.
If program execution has been halted by STOP, END or Ctrl C, the CONT
command causes execution to resume at the next instruction — not the
next line number. Nothing is cleared. If there is no halted program, then
CONT has no effect. After reset Ctrl C return the program may not CONTinue
to execute properly, since some program pointers and stacks will have been
cleared.
39
If an INPUT statement is halted by Ctrl C, an attempt to CONTinue execution
results in a
? SYNTAX ERROR IN linenura
message, where linenum is the line number of the line containing the INPUT
statement.
Executing CONT will result in the
?CAN'T CONTINUE ERROR
message if, after the program's execution halts, the user
a) modifies or deletes any program line.
b) attempts any operation that results in an error message.
However, program variables can be changed using immediate-execution
commands, as long as no error messages are incurred.
If DEL Is used In a deferred execution statement, the specified lines are
deleted and then program execution halts. An attempt to use CONT under
these circumstances will cause the
? CAN'T CONTINUE ERROR
message.
If CONT is used in a deferred execution statement, the program's execution
is halted at that statement, but control of the computer is not returned
to the user. The user can regain control of the computer by issuing a Ctrl
C command, but an attempt to CONTinue program execution in the next
statement merely relinquishes control to the halted program again.
TRACE imra i def
NOTRACE imm 4 def
TRACE
NOTRACE
TRACE sets a debug mode that displays the line number of each statement as
It is executed. When the program also prints on the screen TRACES may be
displayed in an unexpected fashion or overwritten. NOTRACE turns off the
TRACE debug mode.
Once set, TRACE is not turned off by RUN, CLEAR, NEW, DEL or reset; reset
Ctrl B turns off TRACE (and eliminates any stored program).
PEEK Imra & def
PEEK (aexpr)
Returns the contents, in decimal , of the byte at address \aexpr\.
Appendix J contains examples of how to use PEEK.
40
POKE imir & def
POKE aexprl, aexpr2
POKE stores an eight bit quantity, the binary equivalent of the decimal
value \aexpr2\, into the location whose address is given by \aexprl\. The
range of \aexpr2\ must be from through 255; that of \aexprl\ must be from
-65535 through 65535. Reals are converted to integers before execution*
Out of range values cause the message
?ILLEGAL QUANTITY ERROR
to be printed.
\aexpr2\ will be successfully stored only if the appropriate receiving
hardware (memory, or a suitable output device) is present at the address
specified by \aexprl\. \aexpr2\ will not be successfully stored at
non-receptive addresses such as the Monitor ROMs or unused Input/Output
ports.
In general, this means that \aexprl\ will be in the range through max,
where max is determined by the amount of memory in the computer. For
instance, on an APPLE II with 16K of memory, max is 15384. If the APPLE II
has 32K of memory, max is 32768; and if the APPLE II has 48K of memory, max
Is 49152.
Many nemory locations contain information which is necessary to the
functioning of computer system. A POKE into these locations may alter the
operation of the system or of your program, or It may clobber APPLESOFT.
WAIT imm 6. def
WAIT aexprl, aexpr2 [, aexpr3]
Allows user to insert a conditional pause into a program. Only reset can
interrupt a WAIT.
\aexprl\ Is the address of a memory location; it must be In the range -65535
through 65535 to avoid the
7ILLEGAL QUANTITY ERROR
message. In practice, \aexprl\ is usually limited to the range of addresses
corresponding to locations at which valid memory devices exist, from
through the maximum value for HIMEM: in your conputer. See HIMEM: and POKE
for more details. Equivalent positive and negative addresses may be used.
\aexpr2\ and \aexpr3\ must be in the range through 255, decimal. When
WAIT is executed, these values are converted to binary numbers in the range
through Ilium.
If only aexprl and aexpr2 are specified, each of the eight bits in the
binary contents of location \aexprl\ la ANDed with the corresponding bit in
the binary equivalent of \aexpr2\- For each bit, this gives a zero unless
both of the corresponding bits are high (1). If the results of this process
41
are eight zeros, then the test is repeated. If any result Is non-zero
(which means at least one high (1) bit in \aexpr2\ was matched by a
corresponding high (1) bit at location \aexprL\), the WAIT is completed and
the APPLESOFT program resumes execution at the next instruction.
WAIT aexprl, 7
causes the program to pause until at least one of the three rightmost bits
at location \aexprl\ is high (1).
WAIT aexprl,
causes the program to pause forever.
If all three parameters are specified, then WAIT performs as follows: first,
each bit in the binary contents of location \aexprl\ is XORed with the
corresponding bit in the binary equivalent of \aexpr3\. A high (1) bit in
\aexpr3\ gives a result that is the reverse of the corresponding bit at
location \aexprl\ (a 1 becomes a 0; a becomes a 1). A low ((3) bit in
\aexpr3\ gives a result that is the same as the corresponding bit at
location \aexprl\. If \aexpr3\ is just zero, the XOR portion does nothing.
Second, each result Is ANDed with the corresponding bit in the binary
equivalent of \aexpr2\. If the final results are eight zeros, the test is
repeated. If any result is non-zero, the WAIT is completed and execution of
the APPLESOFT program continues at the next instruction.
Another way to look at WAIT: the object is to test the contents of location
\aexprl\ to see when any one of certain bits is high (1, or on) or any
one of certain other bits is low (0, or off). Each of the eight bits in
the binary equivalent of \aexpr2\ Indicates whether you are interested in
the corresponding bit at location \aexprl\: 1 means you're interested,
means ignore that bit. Each of the eight bits In the binary equivalent of
\aexpr3\ indicates which state you are WAITing for the corresponding bit in
location \aexprl\ to be in: 1 means the bit must be low, zero means the bit
must be high. If any of the bits in which you have indicated interest (by
a 1 in the corresponding bit of \aexpr2\) matches the state you specified
for that bit (by the corresponding bit of \aexpr3\) the WAIT is over. If
aexpr3 is omitted, its default value is zero.
For instance:
WAIT aexprl, 255, means pause until at least one of the
8 bits at location \aexprl\ is high.
WAIT aexprl, 255 Identical to the above, in operation.
WAIT aexprl, 255, 255 means pause until at least one of the
8 bits at location \aexprl\ Is low.
WAIT aexprl, 1, 1 means pause until the rightmost bit
at location \aexprl\ is low, regardless
of the states of the other bits.
WAIT aexprl, 3, 2 means pause until either the rightmost
bit at location \aexprl\ is high, or
the next-to-rightmost bit is low, or
both conditions exist.
42
This program pauses until you type any character whose ASCII code (see
Appendix K) is even :
IW POKE -16368, : REM RESET KEYBOARD STROBE (HIGH BIT)
105 REM PAUSE UNTIL KEYBOARD STROBE IS SET BY ANY KEY.
110 WAIT -16384, 128 : REM WAIT UNTIL HIGH BIT IS ONE.
115 REM PAUSE SOME MORE UNTIL KEY STRUCK IS EVEN.
120 WAIT -16384, 1,1: REM WAIT UNTIL LOW BIT IS ZERO.
130 PRINT "EVEN"
140 GOTO 100
CALL inm & def
CALL aexpr
Causes execution of a machine-language subroutine at the memory location
whose decimal address Is specified by \aexpr\.
\aexpr\ must be in the range -65533 through 65535 or the message
? ILLEGAL QUANTITY ERROR
is displayed. In practice, \aexpr\ is usually limited to the range of
addresses for which valid memory devices exist, from through the maximum
value for HIMEM: in your computer. See HIMEM: and POKE for more details.
Equivalent positive and negative addresses may be used interchangeably. For
instance, "CALL -936" and "CALL 64600" are identical.
Appendix J contains examples of the use of CALL.
HIMEM; imm & def
HIMEM: aexpr
Sets the address of the highest memory location available to a BASIC
program, including variables. It is used to protect the area of memory above
it for data, graphics or machine language routines.
\aexpr\ must be in the range -65535 through 65535, inclusive, to avoid the
? ILLEGAL QUANTITY ERROR
message. However, programs may not execute reliably unless there is
appropriate memory hardware at the locations specified by all addresses up
to and including \aexpr\.
In general, the maximum value of aexpr is determined by the amount of memory
in the computer. For Instance, on an APPLE II with 16K of memory \aexpr\
would be 16384 or less. If the APPLE II has 32K of memory, \aexpr\ could be
as high as 32768; and if the APPLE II has 48K of memory, \aexpr\ could be as
high as 49152.
Normally, APPLESOFT automatically sets HIMEM: to the highest memory address
available on the user's computer, when APPLESOFT is first invoked.
43
The current value of HIMEM; Is stored in memory locations 116 and 115
(decimal). To see the current value of HIMEM:, type
PRINT PEEK(116)*256 + PEEK(1I5)
If HIMEM: sets a highest memory address which is lower than that set by
LOMEM:, or which does not leave enough memory available for the program to
run, the
?OUT OF MEMORY ERROR
is given.
\aexpr\ may be in the range increasing to 65535, or in the equivalent
range -65535 increasing to -1. Equivalent positive and negative values may
be used interchangeably.
HIMEM: is not reset by CLEAR, RUN, NEW, DEL, changing or adding a program
line, or reset. HIMEM: is^ reset by reset Ctrl B return, which also erases
any stored program.
LOMEM: imm 6, def
LOMEM: aexpr
Sets the address of the lowest memory location available to a BASIC program.
This is usually the address of the starting memory location for the first
BASIC variable. Normally, APPLESOFT automatically sets LOMEM: to the end of
the current program, before executing the program. This command allows
protection of variables from high-resolution graphics in computers with
large amounts of memory.
\aexpr\ must be in the range -65535 through 65535, inclusive, to avoid the
7ILLEGAL QUANTITY ERROR
message. However, if LOMEM: is set higher than Che current value of HIMEM:,
the message
?OUT OF MEMORY ERROR
is displayed. This means that \aexpr\ must be lower than the maximum
value that can be set by HIMEM: (See HIMEM: for a discussion of Its maximum
value. )
If LOMEM: is set lower than the address of the highest memory location
occupied by the current operating system (plus any current stored program),
the
?OUT OF MEMORY ERROR
message is again displayed. This imposes an absolute lower limit on \aexpr\
of about 2(J51 for firmware APPLESOFT.
LOMEM: Is reset by NEW, DEL, and by adding or changing a program line.
LOMEM: is reset by reset Ctrl B, which also deletes any stored program. It
is not reset by RUN, reset Ctrl C return or reset 0G return.
The current value of LOMEM: is stored in memory locations 106 and 105
(decimal). To see the current value of LOMEM:, type
PRINT PEEK ( 106 )*256 + PEEK (105)
44
Once set, unless it is first reset by one of the above commands, LOHEM : can
be set to a new value only if the new value is higher (in memory) than Che
old value. An attempt to set a lower LOMEM: than the value still in effect
gives the
?OUT OF MEMORY ERROR
message.
Changing EOMEM: during the course of a program may cause certain stacks or
portions of the program to be unavailable, so that the program will not
continue to execute properly.
Equivalent positive and negative addresses may be used interchangeably.
USR i nim ^ def
USR (aexpr)
This function passes \aexpr\ to a machine-language subroutine.
The argument aexpr is evaluated and put into the floating point accumulator
(locations $9D through $A3), and a JSR to location $0A Is perforraed.
Locations $0A through $00 must contain a JMP to the beginning location of
the machine-language subroutine. The return value for the function is
placed in the floating point accumulator.
To obtain a 2-byte integer from the value in the floating-point accumulator,
your subroutine should do a JSR to $E10C. Upon return, the integer value
will be in locations 5A0 (high-order byte) and $A1 (low-order byte).
To convert an integer result to its floating-point equivalent, so that the
function can return that value, place the two-byte integer in registers A
(high-order byte) and Y (low-order byte). Then do a JSR to $E2F2. Upon
return, the floating-point value will be in the floating-point accumulator.
To return to APPLESOFT, do an RTS.
Here is a trivial program using Che USR function, just to show you the
format :
] reset
* 0A:4C 00 03 reCurn
* 0300:60 return
* Ctrl C return
] PRINT USR(8)*3
24
At location S0A, we put a JMP (code 4C) to location S300 (low-order byte
first, then high-order byte). At location $300, we put an RTS (code 60).
Back in APPLESOFT, when USR (8) was encountered the argument 8 was placed in
the accumulator, the Monitor did a JSR to location 50A where it found a JMP
to S300. In S300 it found an RTS which sent it back to APPLESOFT. The
value returned was Just the original value 8 in the accumulator, which
APPLESOFT then multiplied by 3 to get 24.
45
EDITING
AND FORMAT-RELATED
COMMANDS
In Chapter 3, also see Ctrl C.
48 LIST
49 DEL
50 REM
50 VTAB
50 HTAB
51 TAB
51 POS
52 SPC
52 HOME
52 CLEAR
53 FRE
53 FLASH, INVERSE and NORMAL
54 SPEED
54 esc A, esc B, esc C and esc D
55 repeat
55 right arrow and left arrow
55 Ctrl X
LIST imm & dpf
LIST [linenuralj [- linenuni2]
LIST [linenuml] [, Iinenum2]
If neither linenuml nor linenum2 is present, with or without a delimiter,
the entire program is displayed on the screen. If linenuml is present
without a delimiter, or if linenuml =linenum2, then just the line numbered
linenuml is displayed. If linenuml and a delimiter are present, then the
program is listed from the line numbered linenuml through the end. If a
delimiter and linenum2 are present, then the program is listed from the
beginning through the line numbered linenum2. If linenuml, a delimiter and
linenum2 are all present, then the program is listed from the line numbered
linenuml through the line numbered Iinenum2, inclusive.
When more than one line is to be listed. If the line numbered linenuml in
the LIST statement does not appear in the program, the LIST command will use
the next greater line number that does appear in the program. If the line
numbered llnenum2 in the LIST statement does not appear in the program, the
LIST command will use the next smaller line number that does appear in the
program.
These all LIST the entire program:
LIST LIST (,|-) LIST (,|-]
LIST linenura,
lists from the line with line number linenum through the end of the program.
LIST , Q
lists the entire program, then gives the
? SYNTAX ERROR
message.
APPLESOFT "tokenizes" your program lines before storing them, removing
unnecessary spaces in the process. When LlSTing, APPLESOFT "reconstitutes"
the tokenized program lines, adding spaces according to its own rules. For
example,
10 C=+5/-6:B=-5
becomes
10 C = + 5 / - 6:B = - 5
when LISTed.
LIST uses a variable line width and various indentations. This can bt a
problem when you are trying to edit or copy a LISTed instruction. To force
LIST to abandon formatting with extra spaces, clear the screen and reduce
the text window to width 33 (maximum):
HOME
POKE 33,33
^
APPLESOFT truncates a line to 239 characters, then LIST adds spaces
liberally. So you can enter many extra characters by leaving out spaces
when typing — LIST adds them back. An attempt to copy your expanded
statement from the screen results in truncation to 239 characters again,
including the spaces added by LIST.
LlSTing is aborted by Ctrl C.
48
DEL Inm S. def
DEL linenuml , linenura2
DEL deletes the range of lines from linenuml to linenum2, inclusive- If
linenuml is not an existing program line number, the next greater line
number in the program is used In lieu of linenuml; if Ilnenura2 is not an
existing program line number, the next smaller program line number is used.
If you don't follow the usual format, DEL's performance varies as indicated
below:
syntax result
DEL ? SYNTAX ERROR
DEL , 7SYHTAX ERROR
DEL ,b ? SYNTAX ERROR
DEL -a[,b] '.'SYNTAX ERROR
DEL 0,b deletes line zero, regardless of the value
of b.
DEL 1 , -b ignored, even if the program's smallest line
number is zero.
DEL a,-b ?SYNTAX ERROR if a is greater than the
program's smallest line number, unless the
program's smallest line number Is zero and
a is one.
DEL a,-b ignored if a is not zero and the only
program line is line number zero.
' CO^ . DEL a,-b ignored if a is not zero and if a is less
than or equal to the program's smallest
line number.
Cjy DEL a[,] ignored.
COv DEL a,b ignored if a is not zero and a is greater
^^ than b.
When used in deferred execution, DEL works as described above, then halts
execution. CONT will not work in this situation.
49
REM iisini & cK r
REM {character I "}
This serves to allow text of any sort to be inserted in a program. All
characters, including statement separators and blanks may be included.
Their usual meanings are ignored. A REM is terminated only by return.
When REMS are listed, APPLESOFT Inserts an extra space after REM, no matter
how many spaces were typed after REM by the user.
VTAK Iehu t. del
VTAB aexpr
Moves the cursor to the line that is \aexpr\ lines down on the screen. The
top line is line 1; the bottom line is line 24. This statement may involve
moving the cursor either up or down, but never to the right or left.
Arguments outside the range 1 to 24 cause the message
7ILLEGAL QUANTITY ERROR
to appear.
VTAB uses absolute moves, relative only to the top and bottom of the
screen : it ignores the text window. In graphics mode, VTAB will move the
cursor into the graphics area of the screen. If VTAB moves the cursor to a
line below the text window, all subsequent printing takes place on that
line.
HTAR iram 4 def
HTAB aexpr
Assume the line in which the cursor is located has 255 positions, 1 through
255. Regardless of the text window width you may have set, positions 1
through 40 are on the current line, positions 41 through 80 are on the next
line down, and so on. HTAB moves the cursor to the position that is \aexpr\
positions from the left edge of the current screen line. HTAB's moves are
relative to the left margin of the text window, but Independent of the line
width. HTAB can move the cursor outside the text window, but only long
enough to PRINT one character. To place the cursor in the leftmost position
of the current line, use HTAB 1.
®
HTAB moves the cursor to position 256.
If \aexpr\ is negative or greater than 255, the message
? ILLEGAL QUANTITY ERROR
is printed.
50
Note that the structures of HTAB and VTAB are not parallel, in that HTABs
beyond the right edge of the screen do not cause the
? ILLEGAL QUANTITY ERROR
message, but cause the cursor to jump to the next lower line and tab
((aexpr-l)MOD 4(3)+i.
TAB 1mm & def
TAB (aexpr)
TAB must be used in a PRINT statement, and aexpr must be enclosed in
parentheses. TAB moves the cursor to the position that is \aexpr\ printing
positions from the left margin of the text window if \aexpr\ is greater than
the value of the current cursor position relative to the left margin. If
\aexpr\ is less than the value of the current cursor position, then the
cursor is not moved — TAB never moves the cursor to the left (use HTAB for
this) .
If TAB moves the cursor beyond the rightmost limit of the text window, the
cursor is moved to the leftmost limit of the next lower line in the text
window, and spacing continues from there.
w
TAB(l*) puts the cursor into position 256.
\aexpr\ must be in the range through 255, or the message
7ILLEGAL QUANTITY ERROR
is presented.
TAB is parsed as a reserved word only if the next non-space character is a
left parenthesis.
POS (expr)
Returns the current horizontal position of the cursor on the screen,
relative to the left hand margin of the text window. At the left margin,
is returned. Although expr is just there to hold the parentheses apart, it
is evaluated anyway, so it must not be illegal. Anything which can be
interpreted as a number, a string or a variable name may be used for expr-
If Gxpr is a set of characters which cannot be a variable name, the
characters must be enclosed in quotation marks.
Note that for HTAB and TAB positions are numbered from I, but for POS and
SPC they're numbered from 0. Therefore
PRINT TAB(23); POS(0)
causes 22 to be printed, while
PRINT SPC (23); POS(0)
causes 23 to be printed.
SI
SPC tram & def
SPC (aexpr)
Must be used in a PRINT statement, and aexpr must be enclosed in
parentheses. Introduces \aexpr\ spaces between the item previously printed
(or, by default, the left margin of the text window), and Che next item to
be printed, if the SPC command concatenated with the items preceeding and
following, by juxtaposition or by intervening semi-colons. SPC ((8) does not
introduce any space.
\aexpr\ must be in the range to 255, inclusive, or the message
7ILLEGAL QUANTITY ERROR
appears. However, one SPC (aexpr) can be concatenated to another In the form
PRINT S?C(25(3)SPC(139)SPC(255)
and so on, to provide arbitrarily large positive spaces.
Note that while HTAB moves the cursor to an absolute screen position
relative to the left margin of the text window, SPC (aexpr) moves the cursor
a given number of spaces away from the previously printed item. This new
position may be anywhere in the text window, depending on the location of
the previously printed item.
Spacing beyond the rightmost limit of the text window causes spacing or
printing to resume at the left edge of the next lower line in the text
window.
When printing in tab fields, spacing may be within a tab field or across
into another tab field, or it may occupy a tab field of its own.
If \aexpr\ Is a real, it is converted to an integer.
SPC is parsed as a reserved word only if the next non-space character is a
left parenthesis.
HOME imm 6. def
HOME
No parameters. Moves cursor to upper left screen position within the
scrolling window and clears all text within the window. This command is
identical to "CALL -936" and to "esc @ return".
CLEAR ifrnii & def
CLEAR
No parameters. Zeroes all variables, arrays and strings. Resets pointers
and stacks.
52
KRF i "im A def
FRE (expr)
FRE returns the amount of memory (in bytes) still available to the user.
You may sometimes wind up with more memory than you expected, since
APPLESOFT stores duplicate strings only once. That is, if A$="PIPPIN" and
B$="PIPPIN" then the string "PIPPIN" will be stored only once.
If the number of free memory bytes exceeds 32767, FRE(expr) returns a
negative number. Adding 65536 to this number gives you the actual number of
free bytes of memory.
FRE(expr) returns the number of bytes remaining below the string storage
space and above the numeric array and string pointer array space (see memory
map in Appendix 1). HIMEM: can be set as high as 65535, but if it is set
beyond the highest RAM memory location In your APPLE, FRE may return a
rather meaningless number exceeding the memory capacity of the computer.
(See HIMEM: and POKE for a discussion of memory limits.)
When the contents of a string are changed during the course of a program,
(e.g. A$ which equaled "cat" becomes A$="dog" ) APPLESOFT does not eliminate
"cat", but just opens new file for "dog". As a result, a lot of old
characters slowly fill down from HIMEM: to the top of the array space.
APPLESOFT will automatically "house-clean" when this old data runs into the
free array space, but if you are using any of the free space for machine
language programs or high-resolution page buffers, they may be clobbered.
Using a statement of the form
X = FRE ((if)
periodically within your program will force the house-cleaning to occur and
prevent such events.
Although expr is just used to hold the parentheses apart, it is evaluated,
so it should not be something illegal.
FLASH 1mm & def
INVERSE imm 6, def
NORMAL imm & def
FLASH
INVERSE
NORMAL
These three commands are used to set video output modes. They do not use
parameters, and they do not affect the display of characters as you type
them t nto the computer nor characters already on the screen..
FLASH sets the video mode to "flashing", so the output from the computer
Is alternately shown on the screen in white on black and then reversed to
black on white.
INVERSE sets the video mode so that the computer's output prints as black
letters on a white background.
NORMAL sets the mode to the usual white letters on a black background, for
both input and output.
§3
SPEED inni h def
SPEED = aexpr
Sets speed at which characters are to be sent to the screen or other
input/output devices. The slowest speed is 0; the fastest speed is 255.
Out of range values will cause the message
?ILLEGAL QUANTITY ERROR
to be displayed.
esc A imm only (editing only)
esc B iimn only (editing only)
esc C iram only (editing only)
esc D imm only (editing only)
The escape key, labeled "ESC", may be used in conjunction with the letter
keys A or B or C or D to move the cursor: to move the cursor one space,
first press the escape key, then release the escape key and press the
appropriate letter key.
moves cursor one
command
sp
ace to the
esc A
right
esc B
left
esc C
down
esc D
up
These escape commands do not affect the characters moved over by the cursor:
the characters remain both on the TV screen and in memory. By themselves,
the escape commands also do not affect the program line being typed.
To change a program line, LIST the line on the screen and use the escape
commands to move the cursor so that It sits directly on the very first
character of the LISTed line. Then use the right-arrow and KEPT keys to
recopy the characters from the screen, typing a different character whenever
the cursor is on a character you wish to change. If you did not LIST the
line, do not copy the prompt character <] ) that appears at the beginning of
the line. Finally, press the RETURN key to store the line or execute
it.
54
repeat imm only (editing nnly)
The repeat key is the key labeled "KEPT". If you hold down Che repeat key
while pressing a character key, the character will be repeated. The first
time you press the repeat key alone, it "repeats" the character last typed.
ri)4ht_ arrow imm only (editing only)
left arrow iiriTD only (editing only)
The right-arrow key moves the cursor to the right. As the cursor moves,
each character it crosses on the screen is copied into
APPLE II's memory , just as if you had typed the character. It Is
used, with the repeat key, to save retyping an entire line when only minor
changes are required.
The left-arrow key moves the cursor to the left. Each time the cursor moves
to the left, one character is erased from the program line
which you are currently typing , regardless of what the cursor is
moving over. The screen is Ignored by this command, and nothing is changed
on the screen.
Unless you are currently typing a line for which return has not yet been
pressed, the left-arrow key has no current program-line characters to erase.
In this case, its use will cause the prompt character (] ) to appear in
column (J of the next lower line, followed by the cursor. That is why the
cursor frequently cannot be moved to column of the TV screen by using the
left-arrow key: a current program-line character must be erased for each
move. For pure moves, without erasing or copying, see the escape commands.
Ctrl X Imra only
Tells the APPLE II to ignore the line currently being typed, without
deleting any previous line of the same line number. A backslash (\) is
displayed at the end of the line to be ignored, and the cursor jumps to
column of the following line. This command can also be used during a
response to an INPUT instruction.
55
CHAPTER
ARRAYS AND STRINGS
58 DIM
59 LEN
59 STR?
59 VAL
60 CHR?
60 ASC
60 LEFTS
61 RIGHTS
61 MIDS
62 STORE and RECALL
DTM imm & def
DIM var subscript [{,var subscript}]
When a DIM statement is executed, it sets aside space for the array with the
name var. Two bytes in memory are used for storing an array variable name,
two for the size of the array, one for the number of dimensions, and two for
each dimension. As discussed below, the amount of space allocated for the
elements of an array depends upon the type of array.
Subscripts range from to \subscript\. The number of elements in an
n-dimensional array is
(\subscriptl\+l)*(\subscript2\+l)*...*(\subscriptn\+l).
E.g. DIM SHOW (4,5,3) sets aside 5*6*A elements (120 elements). Typical
elements are:
SHOW (4,4,1)
SHOW (0,0,2)
and so on.
The maximum number of dimensions for an array is 88, even if each dimension
can contain only one element:
DIM A(0,(},...0) where there are 89 zeros gives an
?OUT OF MEMORY ERROR
but DIM A(2,0,...0) where there are 88 zeros does not.
In practice, however, the size of arrays is often limited much more by the
amount of memory available. Each integer array element occupies 2 bytes (16
bits) in memory. Each real array element occupies 5 bytes (40 bits) in
memory. String array variables use 3 bytes for each element (one for
length, two for a location pointer), stored as an integer array when the
array is DIMensioned. As the strings themselves are stored by the program,
they occupy an additional one byte per character. See page 137 for map.
If an array element is used in a program before that variable is
DIMensioned, APPLESOFT assigns a maximum subscript of 10 for each dimension
in the element's subscript.
Using a variable whose subscript is larger than the maximum designated, or
which calls for a different number of dimensions than specified in a DIM
statement, causes the
?BAD SUBSCRIPT ERROR
message to appear.
If the program DIMensions an array that has the same name as a previously
DIMensioned array (even if DIMensioned by default usage), then the message
?REDIM'D ARRAY ERROR
appears.
The individual strings in a string array are not dimensioned, but grow and
shrink as necessary. The statement
WARD$(5) = "ABODE"
creates a string of length 5. The statement
WARD$(5) = ""
de-allocates the space allotted to the string WARD$(5). A string may
contain a maximum of 255 characters.
Array elements are set to zero when RUN or CLEAR are executed.
58
LEN 1mm ^ def
LEN (sexpr)
This function returns the number of characters in a string, between and
255. If the argument is a concatenation of strings whose combined length is
greater than 255, the message
7STRING TOO LONG ERROR
is given.
STRS imm & def
STRS (aexpr)
This function converts \aexpr\ into a string which represents that value.
aexpr Is evaluated before it is converted to a string. STR$(100 000 000
00(J) returns lE+11.
If \aexpr\ exceeds the limits for reals, then the message
?OVERFLOW ERROR
is displayed.
VAL imm & def
VAL (sexpr)
This function attempts to interpret a string as a real or an integer,
returning the value of that number.
The first character of the string must be a possible item in a number
(leading spaces are acceptable), or is returned. Each character
thereafter is likewise examined, until the first definitely non-numeric
character is encountered (intervening spaces, decimal points, + and - signs,
and E are all possible numeric characters in the correct context). The
first non-numeric character and all subsequent characters are ignored, and
the string to that point is evaluated as a real or an integer.
If a string concatenation consisting of more than 255 characters is the
argument of VAL, the message
7STRING TOO LONG ERROR
is given.
If the absolute value of the number returned is greater than 1E38, or if the
number contains more than 38 digits (including trailing zeroes), the message
70VERFL0W ERROR
is presented.
59
CHR$ iram & def
CHR? (aexpr)
A function that returns the ASCII character which corresponds to the value
of aexpr. \aexpr\ must be between and 255, inclusive, or the message
7ILLEGAL QUANTITY ERROR
appears. Reals are converted to integers.
ASC imra t. dof
ASC (sexpr)
This function returns an ASCII code (not necessarily the lowest number) for
the first character of \sexpr\. ASCII codes in the range 96 through 255
will generate characters on the APPLE which repeat those in the range
through 95. However, although CHR$(65) returns an A and CHR$(193) also
returns an A, APPLESOFT does not recognize the two as the same character
when using string logical operators.
If a string is the argument, it must be enclosed in quotation marks, and
quotation marks may not be Included within the string. If the string is
null, the message
7ILLEGAL QUANTITY ERROR
is given.
An attempt to use the ASC function on Ctrl @ results in the
? SYNTAX ERROR
message.
LEFTS inim & def
LEFT$ (sexpr, aexpr)
This function returns the first (leftmost) \aexpr\ characters of \sexpr\:
PRINT LEFTS ("APPLESOFT", 5)
APPLE
No part of this command can be omitted. If \aexpr\<;l or \aexpr\>255 then
the message
? ILLEGAL QUANTITY ERROR
is displayed. If \aexpr\ is a real, it is converted to an integer.
If \aexpr\ > LEN(sexpr), only the characters which constitute the string are
returned. Any extra positions are ignored.
If "$" is omitted from the command name, APPLESOFT treats LEFT as an
arithmetic variable name and the message
?TYPE MISMATCH ERROR
is displayed.
60
RIGHTS imm 6. del
RIGHT$ (sexpr, aexpr)
This function returns the last (rightmost) \aexpr\ characters of \sexpr\:
PRINT R1GHT$ ("APPLESOFT" + "WARE", 8)
SOFTWARE
No part of this command may be omitted. If \aexpr\ >= LEN (sexpr) then
RIGHTS returns the entire string. The message
TILLEGAL QUANTITY ERROR
Is displayed if \aexpr\<l or \aexpr\>255,
RIGHTS (sexpr , aexpr) = MID$(sexpr, LEN (sexpr )+I-\aexpr\ )
If the "$" is omitted from the command name, APPLESOFT treats RIGHT as an
arithmetic variable name and the message
?TYPE MISMATCH ERROR
is displayed.
MID? imm 6. def
MIDS (sexpr, aexpri [, aexpr2))
MID$ called with two arguments returns the substring starting at the
\aexprl\th character of \sexpr\, and proceeding through the last character
of \sexpr\.
PRINT MID$("APPLESOFT", 3)
PLESOFT
MID$(sexpr, aexpr) = RIGHTS (sexpr , LEN (sexpr ) + l-\aexpr\ )
MIDS called with three arguments returns \aexpr2\ characters of \sexpr\,
beginning with the \aexprl\th character and proceeding to the right.
PRINT MIDS ("APPLESOFT", 3, 5)
PLESO
If \aexprl\>LEN (sexpr), then MID$ returns a null string. If
\aexpr l\+\aexpr2\ exceeds the length of \sexpr\ (or 255, the maximum length
of any string), any extra is ignored. MID$(AS, 255, 255) returns one
character if LEN(A$)=255, otherwise the null string is returned.
If either \aexprl\ or \aexpr2\ are outside the range 1 through 255,
inclusive, then the message
7ILLEGAL QUANTITY ERROR
is displayed.
If the S is omitted from the command name, APPLESOFT treats MID as an
arithmetic variable name and the message
7TYPE MISMATCH ERROR
is displayed.
61
STORE imm 6. def
RECALL 1mm & def
STORE avar
RECALL avar
These commands store and recall arrays from cassette tape.
Array names are not stored with their values, so an array may be read back
using a different name than that used with the STORE command.
The dimensions of the array named by the RECALL statement should be
Identical to the dimensions of the original array as it was STOREd. For
example, if an array dimensioned by DIM A(5,5,5) is STOREd, then one might
RECALL it into an array dimensioned by DIM 5(5,5,5). Failure to observe
this will result in scrambled numbers in the RECALLed array, extra zeros in
the array, or the ?OUT OF MEMORY ERROR.
In general, you will be given the ?OUT OF MEMORY ERROR message only when the
total number of elements reserved for the array being RECALLed is
Insufficient to contain all of the elements of the array that was STOREd.
DIM A (5, 5, 5)
STORE A
saved 6*6*6 elements on the cassette tape-
DIM B(5,35)
RECALL B
will result in the message
ERR
and scrambled numbers in array B, but program execution will continue.
However,
DIM B(5,25)
RECALL B
will cause the
?OUT OF MEMORY ERROR
to be displayed, and program execution will cease. In this case, array B
contained 6*26 elements — too few elements to contain all the elements of
array A.
If the array RECALLed has the same number of dimensions [ DIM A(5,5,5)
specifies an array of three dimensions, each of size 6] as the array which
was STOREd, any of the dimensions of the RECALLed array may be larger than
the corresponding dimension of the STOREd array. However, scrambled numbers
in the RECALLed array will result unless it is the last dimension of the
RECALLed array which Is larger than the last dimension of the STOREd array.
In every case you will find extra zeros stored in the excess elements of the
RECALLed array, but only in this last case will you find the zeros where you
would expect them. After storing an array with
DIM A(5,5,5)
STORE A
you will find that
DIM B(I0,3,5)
RECALL B
and also
DIM 8(5,1(3,5)
RECALL B
62
both fill array B with mixed-up numbers from array A; while
DIM B(5,5,lSt)
RECALL B
works fine, with zeros in array B's extra elements.
We have discussed two "rules" for STOREing and RECALLing arrays with equal
numbers of dimensions:
1. Only the last dimension of the array RECALLed may be larger than
the last dimension of the array STOREd.
2. The total number of elements RECALLed must at least equal th
number of elements STOREd.
If rule 2. is followed, and if rule 1. Is followed for the dimensions which
are common to both arrays (these must be the first dimensions), then one may
RECALL an array with more dimensions than the array that was STOREd. An
ERR message is displayed, but program execution continues.
DIM B(5,5,5,5)
RECALL B
will work fine in the above example (after the ERR message, and with many
extra zeros in array B), but
DIM B(5,5,3,5)
RECALL B
will fill array B with scrambled numbers (after the ERR message), and
DIM B(5,5,l, 1)
RECALL B
will cause the
?OUT OF MEMORY ERROR
because the 6*6*2*2 elements in array B are fewer than the 6*6*6 elements
STOREd in array A.
Only real and integer arrays may be stored. String arrays must be converted
to an integer array using the ASC function in order to be stored.
Although STORE and RECALL refer to their variables without mention of
subscript or dimension, only arrays may be STOREd or RECALLed. The
program
100 A(3) = 45
110 A = 27
120 STORE A
stores on tape the array elements A(0) through A(10) (by default, the
array is dimensioned to eleven elements), not the variable A (which equals
27 in the program).
There is no prompting message or any other signal issued by the STORE
instruction; the user must have the recorder running in record mode when the
instruction is executed. A "beep" signals the beginning of the recording,
and another "beep" signals the end.
The program
300 DIM B(5,13)
310 B = 4
320 RECALL B
reads from tape the 84 (6*14) array elements B(0,0) through B(5,13). The
value of the variable B is not changed.
Again, there is no prompting message; "beeps" signal the beginning and the
end of the recording.
63
If either STORE or RECALL contains an array name not previously DIMensioned
or used with a subscript, the message
?OUT OF DATA ERROR
Is given. In immediate-execution mode, if either STORE or RECALL refers to
an array name that is defined in a deferred-execution program line, then the
deferred-execution program line must have been executed prior to the STORE
or RECALL.
STORE and RECALL can be interrupted only by reset.
If the reserved words STORE or RECALL are used as the first characters of
any variable name, the commands may be executed before any
7SYNTAX ERROR
message Is given. The statement
ST0REH0USE=5
will cause the
?OUT OF DATA ERROR
message, unless an array has been defined whose name begins with the
characters HO. In the later case, APPLESOFT will attempt to STORE the
array: first you'll hear one beep, then a second; finally the message
? SYNTAX ERROR
will be printed as APPLESOFT tries to parse the rest of the statment, "=5".
To cut short the beeps and error message you can press the RESET key.
The statement
RECALLOUS=23A
will cause the
?OUT OF DATA ERROR
message to be displayed, unless an array has been defined whose name begins
with the characters OU. In the latter case, APPLESOFT will wait
Indefinitely for an array to arrive from the cassette recorder. The only
way to regain control of the computer is to press the RESET key.
64
INPUT/OUTPUT
COMMANDS
In Chapter 3, also see LOAD and SAVE;
in Chapter 5, see STORE and RECALL.
66 INPUT
67 GET
68 DATA
69 READ
7t) RESTORE
70 PRINT
71 IN#
72 PR//
72 LET
73 DEF FN
INPUT def
INPUT [string ;] var [{, var}]
If the optional string is left out, INPUT prints a question mark and waits
for the user to type a number (if var is an arithmetic variable) or
characters (if var is a string variable). The value of this number or
string is put into var.
When the string is present, it is printed exactly as specified; no question
mark, spaces, or other punctuation are printed after the string. Note that
only one optional string may be used. It must appear directly after "INPUT"
and be followed by a semi-colon .
INPUT will accept only a real or an Integer as numeric input, not an
arithmetic expression. The characters space, +, -, E, and the period are
legitimate parts of numeric Input. INPUT will accept any of these
characters or any concatenation of these characters in acceptable form (e.g.
+E- is acceptable, +- is not); such input by itself evaluates as 0.
In numeric input, spaces in any position are ignored. If numeric Input
which is not a real, an integer, a comma or a colon, the message
?REENTER
is displayed and the INPUT instruction re-executed.
If ONERR GOTO Is used, with another GOTO in the error handling routine to
return the program to the offending INPUT statement, the 86th INPUT error
may cause the program to jump to the Monitor. To recover, use reset Ctrl C
return. This problem can be avoided by using RESUME to return to the INPUT
statement.
Similarly, a response assigned to a string variable must be a single string
or literal, not a string expression. Spaces preceding the first character
are Ignored. If the response is a string, then a quotation mark anywhere
within the string will cause a
7REENTER
message. However, within a string, all characters except the quotation
mark, Ctrl X and Ctrl M are accepted as characters for the string. This
includes the colon and the comma. Spaces following the final quotation mark
are ignored.
If the response is a literal, then quotation marks are accepted as
characters in any part of the literal except the first non-space character.
Spaces following the last character are accepted as part of the literal.
However, the comma and the colon (and Ctrl X and ctrl M) are not accepted as
characters in the literal.
If the user simply presses the RETURN key when a numeric response is
expected, the message
7REENTER
is printed and the INPUT instruction is re-executed. If the RETURN key
alone is typed when a string response is expected, the response is
interpreted as the null string and program execution continues.
66
Successive variables get successively typed values. String variables and
arithmetic variables may be mixed in the same INPUT statement, but the
user's responses must each be of the appropriate type. The typed responses
may be separated by commas or returns. As a result, if a user types commas
in a response that does not begin with a quotation mark, the commas are
interpreted as response separators. This is true even when only one
response is expected.
If a colon is typed in an INPUT response that does not begin with a
quotation mark, all characters typed subsequently are ignored. After a
colon, commas are also ignored, so the start of another response must be
signaled by a return.
If a return is encountered before all the var's have been assigned
responses, two question marks are printed to indicate that an additional
response is expected. When a return is encountered, if the response
contains more response fields than the statement expected, or if a colon
exists in the final expected response (but not within a string), then the
message
? EXTRA IGNORED
is printed and program execution continues.
If a colon or a comma is the first character of an INPUT response, the
response is evaluated as zero or as the null string.
Note that in the INPUT command the optional string must be followed by a
semi-colon but variables must be separated by commas .
Ctrl C can Interrupt an INPUT statement, but only if it is the first
character typed. The program halts when return is typed. An attempt to
CONTinue execution after such a halt results in the
? SYNTAX ERROR
message. Ctrl C is treated as any other character if it is not the first
character typed.
Trying to use the INPUT command in direct execution mode causes the
? ILLEGAL DIRECT ERROR
message.
GET def only
GET var
Fetches a single character from the keyboard without displaying it on the
screen and without requiring that the RETURN key be pressed.
The behavior of GET svar has a few surprises:
Ctrl (^ returns the null character.
The result of GETting a left-arrow or Ctrl H may also
PRINT as if the null character were being returned.
Ctrl C is treated as any other character; it does
not interrupt program execution.
67
While APPLESOFT was not designed or intended to GET values for arithmetic
variables, you may use
GET avar
subject to the following stringent limitations:
^^ GETting a colon or a comma results In the
'^JO^ ?EXTRA IGNORED
message, followed by the return of a zero as the
typed value.
The plus sign, minus sign, Ctrl @, E, space and the
period all return a zero as the typed value.
Typing a return or non-numeric input causes the
7SYNTAX ERROR
message to be displayed.
With ONERR GOTO. . .RESUME, two consecutive GET errors
will cause the system to hang until RESET is pressed.
If GOTO is substituted for RESUME, all is well until
the 43rd GET error (in any order), when the program
jumps to the Monitor. To recover, use
reset Ctrl C return.
Because of these limitations, it is recommended that serious programmers GET
numbers using
GET svar
and convert the resulting string to a number using the VAL function.
DATA def onlv
DATA [literal Istrlng I real I integer] [{, [literal Istring | real | integer] }]
This statement creates a list of elements which can be used by READ
statements. In order of instruction line number, each DATA statement adds
its elements to the list of elements built up by the programs's previous
(lower line number) DATA statements.
The DATA statement does not have to precede the READ statement in a program;
DATA statements can appear anywhere throughout the program.
DATA elements which are READ into arithmetic variables generally follow the
same rules as for INPUT responses assigned to arithmetic variables.
However, the colon cannot be included as a character in a numeric DATA
element.
If Ctrl C is a DATA element, it does not stop the program, even when it is
66
the first character of an element. With this exception, DATA elements which
are READ into string variables follow the same rules as for INPUT responses
assigned to string variables:
Either strings or literals may be used, or both.
Spaces before the first character and following a string are always
ignored.
Any quotation mark that appears within a string causes the
7SYNTAX ERROR message, but all other characters are accepted as
characters in that string, including the colon and the comma
(but not including Ctrl X and Ctrl M).
If an element is a literal , then the quotation mark is accepted as a
valid character anywhere In the literal except as the first non-space
character; the colon, the comma, Ctrl X, and Ctrl M are not accepted.
See INPUT for more details.
DATA elements may be any mixture of reals, integers, strings and literals.
If the READ statement attempts to assign a DATA element that is a string or
a literal to an arithmetic variable, the
? SYNTAX ERROR
message is given for the appropriate DATA line.
If the list of elements in a DATA statement contains a "non-existent"
element, then a zero (numeric) or the null string is returned for that
element depending on the variable to which the element is assigned. A
"non-existent" element occurs in a DATA statement when any of the following
is true:
1) There is no non-space character between DATA and return.
2) Comma is the first non-space character following DATA.
3) There is no non-space character between two commas.
4) Comma is the last non-space character before return.
So when this statement is READ
100 DATA,,
it can return up to three elements consisting of zeros or null strings.
When used in immediate execution mode, DATA does not cause a SYNTAX ERROR,
but its data elements are not available to a READ statement.
READ iram & def
READ var [{,var>]
When the first READ statement is executed in a program, its first variable
takes on the value of the first element in the DATA list (the DATA list
consists of all the elements from all the DATA statements in the stored
program). The second variable (if there Is one) takes on the value of the
second element in the DATA list, and so on. When the READ statement
finishes execution, it leaves a data list pointer after the last element
69
of data used. The next READ statement executed (If any) begins using the
data list from the position of the pointer. Either RUN or RESTORE sets the
pointer to the first element in the DATA list.
An attempt to READ more data than the data list contains produces the
message:
?OUT OF DATA ERROR IN linenum
where linenum is the line number of the READ statement which asked for
additional DATA.
In immediate mode, you can only READ elements from DATA statements which
exist as lines in a currently stored program. The elements of DATA in a
stored program can be READ even if the stored program has not been RUN. If
no DATA statement has been stored, the message
?OUT OF DATA ERROR
is displayed. Executing a program in immediate mode does not set the data
list pointer to the first element in the DATA list.
Extra data left unread is OK.
KKSTORI-: I'mm J. def
RESTORE has no parameters or options. This statement merely moves the data
list pointer (see the READ and DATA statements) back to the beginning of the
data list.
PRINT imm 6. def
PRINT [(expr) ({,1; !{expr>]}]] l,|;]
PRINT { ; }
PRINT {,}
The question mark ( ? ) may be used as an abbreviation for PRINT; it LISTs
as PRINT.
Without any options, PRINT causes line feed and return to be executed on the
screen. When options are exercised, the values of the list of the specified
expressions are printed. If neither a comma nor a semi-colon ends the list,
a line feed and return are executed following the last item printed. If an
item on the list is followed by a comma, then the first character of the
next item to be printed will appear in the first position of the next
available tab field.
The first tab field comprises the leftmost 16 printing positions in the text
window, positions 1 through 16. The second tab field occupies the next 16
positions (17 through 32), and is available for tab-field printing only if
nothing is printed in position 16. The third tab field consists of the
remaining 8 printing positions (33 through 40), and is available only if
nothing is printed in positions 24 through 32.
The size of the scrolling window for text may be changed using various POKE
commands (see Appendix J).
70
The PRINT tab field 3 does not function properly if the text window is set
to less than 33 positions wide; the first character may be printed outside
the text window. HTAB can also cause PRINT to display a first character
outside the text window.
If an item on the list is followed by a semi-colon, then the next item is
concatenated: it is printed directly afterward with no intervening spaces.
Items listed without intervening commas or semi-colons are concatenated if
the items can be parsed without syntax problems. This is best illustrated
by examples:
A=l : B=2 : C=3 : C(4)=5 : C5=7
PRINT 1/3(2*4)51 , : PRINT 1 (A) 2 (B) 3C (4 )C5
.333333333851 1122357
PRINT 3.4.5.6. , : PRINT A."B."C.4
3.4.5.6(^ HaB.3.4
PRINT works very hard to figure out what you want. If it can't interpret a
period as a decimal point, it treats it as the number 0, as illustrated in
the above examples.
PRINT followed by a list of semi-colons does nothing more than PRINT alone,
but it is legal. PRINT followed by a list of commas spaces one tab field
per comma, up to a limit of 239 characters per instruction.
PRINT AS+B$
gives a
?STRING TOO LONG ERROR
if the length of the concatenated strings Is greater than 255. However, you
can print the apparent concatenation using
PRINT A$ BS
without worrying about its length.
IN# imm & def
IN# aexpr
Selects input from slot \aexpr\. Used to specify which peripheral will be
providing input for subsequent INPUT statements. Peripherals may be in
slots 1 through 7, as indicated by \aexpr\.
IN// Indicates that subsequent input will be from the keyboard instead of
the peripheral. Slot is not addressable from APPLESOFT for use with a
peripheral device.
71
If no peripheral is in slot \aexpr\, the system will hang. To recover, use
reset ctrl C return.
If \aexpr\ is less than or greater than 255, the message
? ILLEGAL QUANTITY ERROR
is displayed.
ij^Qj
If \aexpr\ is in the range 8 through 255, APPLESOFT is altered in
unpredictable ways.
For similar transfer of output, see PR//.
PV.lt Inrni 6. def
PR# aexpr
PR// transfers output to slot \aexpr\, where \aexpr\ must be in the range 1
to 7, inclusive.
PR// returns output to the TV screen, not to slot 0.
If no peripheral is in the specified slot, the system will hang. To
recover, use reset ctrl C return.
If \aexpr\ is less than or greater than 255, the message
? ILLEGAL QUANTITY ERROR
is displayed.
I^ft
If \aexpr\ is in the range 8 through 255, APPLESOFT is altered in
unpredictable ways.
For similar transfer of input, see IN//.
LET imm & def
[LET] avar [subscript] = aexpr
[LET] svar [subscript ] = sexpr
The variable name on the left is assigned the value of the string or
expression on the right. The LEI is optional:
LET A=2
and
A=2
are equivalent.
72
The message
?TYPE MISMATCH ERROR
is displayed if you try Co give
a) a string variable name to an arithmetic expression, or
b) a string variable name to a literal, or
c) an arithmetic variable name to a string expression.
If you try to give an arithmetic variable name to a literal, APPLESOFT
attempts to parse the literal as an arithmetic expression.
DEI- de£
FN imm & def
DEF FN name (real avar) = aexprl
FN name (aexpr2)
Allows user to define functions in a program. First the function FN name is
defined using DEF. Once the program line DEFlning the function has been
executed, the function may be used in the form FN name (argument) where the
argument aexpr2 may be any arithmetic expression. The DEFinition's aexprl
may be only one program line in length; the defined FN name may be used
wherever arithmetic functions may be used in APPLESOFT.
Such functions may be reDEFined during the course of a program. The rules
for using arithmetic variables still apply. In particular, the first two
characters of name must be unique. When these lines
10 DEF FN ABC(1)=C0S(I)
20 DEF FN ABT(I)=TAN(1)
are executed, APPLESOFT recognizes the definition of an FN AB function in
line 10; in line 20, the FN AB function is redefined.
In the DEF instruction, real avar is a dummy variable. When the
user-defined function FN name is used later, it is called with an argument
aexpr2. This argument is substituted for real avar wherever it appears in
the definition's aexprl. aexprl may contain any number of variables , but
of course only one of those (at most) corresponds to the dummy variable real
avar, and therefore corresponds to the argument variable.
The DEFinition's real avar need not appear In aexprl. In that case, when
the function is used later in the program, the function's argument is
Ignored in evaluating aexprl. Even in this case, however, the function's
argument Is evaluated Itself, so it must be something legal.
For Instance:
100 DEF FN A(W) = 2 * W + W
110 PRINT FN A(23)
120 DEF FN B(X) = 4 + 3
130 G = FN B{23)
140 PRINT G
150 DEF FN A(Y) = FN B(Z) + Y
160 PRINT FN A(G)
RUN
69 [ FN A(23)=2*23+23 ]
7 [ FN B(anything)=7 ]
14 [ new FN A(7)=7+7 ]
73
If a deferred-execution DEF FN name statement is not executed prior to using
FN name, the
?UNDEF'D FUNCTION ERROR
message is displayed.
User-defined string functions are not allowed. Functions defined using an
integer nameZ for name or for real avar are not allowed.
When a new function is defined by a DEF statement, 6 bytes in memory are
used to store the pointer to the definition.
74
CHAPTER i
COMMANDS RELATING
TO FLOW OF CONTROL
76 GOTO
75 IF... THEN and IF... GOTO
73 FOR... TO... STEP
79 NEXT
79 GOSUB
89 RETURN
80 POP
81 ON... GOTO and ON. ..GOSUB
81 ONERR GOTO
82 RESUME
GOTO Imm 5. dof
GOTO linenum
Branches to Che line whose line number Is linenum. If there is no such
line, or if linenum is absent from the GOTO statement, then the message
?UNDEF'D STATEMENT ERROR IN linenum
is displayed, where linenum is the line number of the program line
containing the GOTO statement.
IF imm & def
IF expr THEN instruction [{: instruction}]
IF expr THEN [GOTO] linenum
IF expr [THEN] GOTO linenum
If expr is an arithmetic expression whose value is not zero (and whose
absolute value is greater than about 2. 93873E-39) , \expr\ is considered to
be true, and any instruction (s) following THEN are executed.
If expr is an arithmetic expression whose value is zero (or whose absolute
value is less than about 2. 93873E-39) , any instructions following THEN are
ignored, and execution passes on to the instruction in the next numbered
line of the program.
When the IF statement occurs in an immediate execution program, if \expr\ is
zero, APPLESOFT will ignore the entire remainder of the program.
If expr is an arithmetic expression involving string expressions and string
logical operators, expr is evaluated by comparing the alphabetic ranking of
the string expressions as determined by the ASCII codes for the characters
involved (see Appendix K).
Statements of the form
IF expr THEM
are valid: no error message is printed.
A THEN without a corresponding IF or an IF without a THEN will cause the
message
? SYNTAX ERROR
to be displayed.
APPLESOFT was not designed or intended to allow the IF statement's expr to
be a string expression, but string variables and strings may be used as expr
under the following stringent conditions.
If expr is a string expression of any Itind, then \expr\ is non-zero, even if
expr is a string variable which has been assigned no value or "0" or the
null string, "". However the literal null string, as in
IF "" THEN ...
evaluates as zero.
76
^
IF string THEN. . .
when executed more than two or three times in a given program, causes the
message
7F0RMULA TOO COMPLEX ERROR
to be printed.
®
If expr is a string variable and the previous statement assigned the null
string to any string variable, then \expr\ evaluates as zero. For
instance, the program
120 IF A$ THEN PRINT "A5"
130 IF B5 THEN PRINT "B$"
140 IF XS THEN PRINT "X$"
when RUN, prints
AS
«$
because strings AS, BS and X5 evaluate as non-zero. However, adding the
line
100 QS = '"■
causes all 3 strings to evaluate as zero, and no output Is printed.
Deleting line 100, or adding almost any line 110, such as
110 F = 3
causes all 3 strings to evaluate as non-zero again.
®
Before THEN, the letter A causes parsing problems:
IF BETA THEN 230
parses to
IF BET AT HEN230
which generates a
? SYNTAX ERROR
message on execution.
These are equivalent:
IF A=3 THEN 160
IF A=3 GOTO 160
IF A=3 THEN GOTO 160
77
FOR imm 6. def
FOR real avar = aexprl TO aexpr2 [STEP aexpr3]
\avar\ Is set to \aexprl-\, and the statements following the FOR are executed
until a statement
NEXT avar
is encountered, where avar is the same name as appears In the FOR statement.
Then \avar\ is incremented by \aexpr3\ (\aexpr3\ defaults to 1). Next
\avar\ is compared to \aexpr2\, and if \avar\>\aexpr2\, execution proceeds
with the statement following the NEXT. If \avar\<=\aexpr2\, execution
proceeds from the statement following the FOR.
If \aexpr3\<0 then operation is slightly different after \aexpr3\ is added
to \avar\. If \avar\<\aexpr2\, execution proceeds with the statement
following the NEXT. If \avar\>=\aexpr2\, then execution proceeds from the
statement following the FOR.
The arithmetic expressions which form the parameters of the FOR loop may be
reals, real variables, Integers, or integer variables. However, real avar
must be a real variable. An attempt to use an integer variable for real
avar results in the
? SYNTAX ERROR
message .
As \avar\ is incremented and compared to \aexpr2\ only at the bottom of the
FOR... NEXT loop, the portion of the program inside the loop is always
executed at least once.
FOR... NEXT loops must not "cross" each other. If they do, the message
?NEXT WITHOUT FOR ERROR
will be printed.
If FOR loops are nested more than 10 levels deep, the
'.'OUT OF MEMORY ERROR
message is displayed.
To run a FOR... NEXT loop in immediate-execution mode, the FOR statement and
the NEXT statement should both be included in the same line (a line is up to
239 characters long).
If the letter A is used immediately prior to TO, do not allow a space
between the T and the 0. FOR I=BETA TO 56 Is fine, but FOR I=BETA T 56
parses as FOR I=BET AT 056 and gets a
7SYNTAX ERROR
on execution.
Each active FOR... NEXT loop uses 16 bytes in memory.
78
NEXT [avarj
NEXT avar [{,avar}!
Forms the bottom of a FOR... NEXT loop. When a NEXT Is encountered, the
program either Ignores it or branches to the statement following the
corresponding FOR, depending on the conditions explained In the discussion
of the FOR statement.
Multiple avars must be specified in the proper order so FOR... NEXT loops are
nested Inside each other and do not "cross over." Incorrectly ordered avars
will cause the message
?NEXT WITHOUT FOR ERROR
to be printed.
A NEXT statement In which no variable name is specified defaults to the most
recently entered FOR-loop that is still in effect. If no FOR statement «lth
the same variable name is in effect, or if no FOR statement of any name is
in effect when a nameless NEXT is encountered, the message
?NEXT WITHOUT FOR ERROR
is printed.
NE5CT without avar executes more rapidly than does NEXT avar.
In immediate-execution mode, the FOR statement and its corresponding NEXT
statement should both be executed in the same line. If a deferred-execution
FOR statement is still in effect, an immediate-execution NEXT statement can
cause a jump to the deferred-execution program, where appropriate. However,
If the FOR statement was executed in Immediate execution, a NEXT statement
in a different immediate-execution line will cause the
7SYNTAX ERROR
unless there are no intervening lines and the NEXT stands alone and
nameless :
IFOR I = 1 TO 5 : PRINT 1
1
JNEKT
2
]NEXT
3
]NEXT I
? SYNTAX ERROR IN xxxx (xxxx is some line number)
GOSUB imra & def
GOSUB llnenum
The program branches to the indicated line. When a RETURN statement is
executed, the program branches to the statement immediately following the
most recently executed GOSUB.
79
Each time a GOSUB Is executed, the address of the following statement is
stored on top of a "stack" of these addresses, so the program can later find
its way back. Each time a RETURN or a POP is executed, the top address in
the RETURN "stack" Is removed.
If the indicated linenum does not correspond to an existing program line,
the error message
?UNDEF'D STATEMENT ERROR IN linenum
is given, where linenum indicates the program line containing the GOSUB
statement. The
IN linenum
portion of the? message Is omitted if GOSUB is used in direct execution mode.
If GOSUBs are nested more than 25 levels deep, the message
?OUT OF MEMORY ERROR
is displayed.
Each active GOSUB (one that has not RETURNed yet) uses 6 bytes of memory.
KKTURN 1mm & def
RETURN
There are no parameters or options In this command. This is a branch to the
statement that immediately follows the most recently executed GOSUB. The
address of the statement branched to is the top one on the RETURN "stack"
(see GOSUB and POP).
If a program encounters RETURN statements once more than it has encountered
GOSUB statements, the message
7RETURN WITHOUT GOSUB ERROR
is presented.
POP imm i def
POP
There are no parameters or options associated with POP. A POP has the
effect of a RETURN without the branch. The next RETURN encountered, Instead
of branching to one statement beyond the most recently executed GOSUB, will
branch to one statement beyond the second most recently executed GOSUB.
It is called a "POP" since It pops one address off the top of the "stack" of
RETURN addresses.
If POP is executed before a GOSUB has been encountered, then the message
?RETURN WITHOUT GOSUB ERROR
is displayed because there are no return addresses on the stack.
80
ON... GOTO def
ON...GOSUB clef
ON aexpr GOTO linenum {[, linenum] }
ON aexpr GOSUB linenum {[, linenum]}
ON... GOTO branches to the line number specified by the \aexpr\th ICGm in the
list of linenums after the GOTO. ON... GOSUB works in a similar fashion, but
a GOSUB rather than a GOTO is executed.
If \aexpr\ is or greater than the number of listed alternate linenums but
less than 256, then program execution proceeds to the next statement.
\aexprl\ must be In the range to 255 to avoid the message
? ILLEGAL QUANTITY ERROR
ONESR arm def (inly
ONERR GOTO linenum
When an error occurs, ONERR GOTO may be used to avoid having an error
message printed and execution halted. The command sets a flag that causes
an unconditional jump (if an error occurs later in the program) to the
program line indicated by linenum. POKE 216, resets the error-detection
flag so that normal error messages will be printed.
The ONERR GOTO statement must be executed before the occurance of an error
to avoid program interruption.
When an error occurs in a program, the code for the type of error is stored
in decimal memory location 222. To see which error was encountered, PRINT
PEEK(222).
Code Error Message Code Error Messase
NEXT without FOR 120 Redimensioned Array
16 Syntax 133 Division by Zero
22 RETURN without GOSUB 163 Type Mismatch
42 Out of DATA 176 String Too Long
53 Illegal Quantity 191 Formula Too Complex
69 Overflow 224 Undefined Function
77 Out of Memory 254 Bad Response to INPUT Statement
90 Undefined Statement 255 Ctrl C Interrupt Attempted
107 Bad Subscript
Care must be taken when handling errors that occur within FOR. . .NEXT loops
or between GOSUB and RETURN, as the pointers and RETURN stacks disturbed.
The error-handling routine must restart the loop, returning to the FOR or
GOSUB statement, not the NEXT or RETURN statement. After error handling,
a return to a NEXT or a RETURN will cause the appropriate message:
?NEXT WITHOUT FOR ERROR or ?RETURN WITHOUT GOSUB ERROR
81
When ONNERR GOTO Is used with RESUME to handle errors in a GET statement,
the program will "hang" If there are two consecutive GET errors without an
Intervening successful GET. To escape, use reset Ctrl C return. If GOTO
ends the error-handling routine, everything works fine (but see next note).
When used in TRACE mode or in a program containing a PRINT statement, ONERR
causes a jump to the Monitor after 43 errors are encountered. Where these
errors are generated by an INPUT statement, everything works fine if RESUME
is used; but if GOTO ends the error-handling routine, the 87th INPUT error
causes a jump to the Monitor. Again, reset Ctrl C return will get you back
to APPLESOFT.
If you are bothered by any of the problems just discussed, execute a CALL to
the following assembly-language subroutine as part of your error-handling
routine*
In the Monitor, enter Hex data; 68 A8 68 A6 DF 9A 48 98 48 60
or in APPLESOFT, enter Decimal data: 104 168 104 166 223 154 72 152 72 96
For example, in APPLESOFT you could POKE the decimal numbers into locations
768 through 777. Then you would use CALL 768 in your error-handling
rout ine.
RESUME def
RESUME
Wlien used at the end of an error handling routine, causes the program to
resume execution at the beginning of the statement in which an error
occurred .
If RESUME is encountered before an error occurs, the
7SYNTAX ERROR IN 65278
message may be given, or other strange events may transpire. Usually, your
program will be stopped or it will "hang."
If an error occurs in an error handling routine, the use of RESUME will
place the program in an infinite loop. Use reset Ctrl C return to escape.
In immediate-execution mode, may cause the system to "hang," may cause a
SYNTAX ERROR, or may begin executing an existing or even a deleted program.
82
CHAPTER'
GRAPHICS AND
GAME CONTROLS
84 TEXT
Low Resolution Gr
84 GR
85 COLOR
85 PLOT
86 HLIN
86 VLIN
87 SCRN
High-resolution Graphics
87 HGR
88 HGR2
89 HCOLOR
89 HPLOT
Game Controls
99 PDL
TEXT imm 6. def
TEXT
No parameters. Sets the screen to the usual full-screen text mode (40
characters per line, 24 lines) from low-resolution graphics mode or either
of the two high-resolution graphics modes. The prompt and cursor are moved
to the last line of the screen. If issued in text mode, TEXT is equivalent
to VTAB 24.
A statement such as
175 TEXTILE=127
causes execution of the reserved word TEXT before the
? SYNTAX ERROR
message appears.
If the text window has been set to anything other than full screen (see
Appendix J), TEXT resets to full screen.
GR imm fit def
GR
No parameters. This command sets low-resolution GRaphics mode (4(3 by 4(3)
for the screen, leaving four lines for text at the bottom. The screen is
cleared to black, and the cursor is moved to the text window. Can be
converted to full-screen (40 by 48) graphics, after executing GR, with the
command
POKE -16302,0
or the equivalent command
POKE 492 34,0
If GR follows a full-screen POKE command, mixed GRaphics-plus-text mode is
reset .
After a GR command, COLOR has been set to zero.
If the reserved word GR is used as the first characters of a variable name,
the GR may be executed before you get the
? SYNTAX ERROR
message. Thus, executing the statement
GRIN=5
leaves you with an unexpectedly darkened screen.
m
If issued while HGR is in effect, GR behaves normally. However, if issued
while HGR2 is in effect, GR clears its usual screenful of memory, but leaves
you looking at page 2 of low-resolution graphics and text. To return to
normal mode, simply type TEXT. In programs, use TEXT before switching from
HGR 2 to GR.
84
CiM (1R inni ^ def
COLOR = aexpr
Sets the color for plotting in low resolution graphics mode. If \aGxpr\ Is
a real, it is converted to an integer. The range of values for \aexpr\ is
from through 255; these are treated modulo 16.
Color names and their associated numbers are
black 4 dark green 8 brown 12 green
1 magenta 5 grey 9 orange 13 yellow
2 dark blue 6 medium blue 19 grey 14 aqua
3 purple 7 light blue 11 pink 15 white
COLOR is set to zero by the GR command.
To find out the COLOR of a given point on the screen, use the SCRN command.
When used in TEXT mode, COLOR is one factor in determining which character
is placed on the screen by a PLOT instruction.
If used while in High-resolution GRaphics mode, COLOR is ignored.
PLOT imm & def
PLOT aexpr 1, aexpr 2
In low-resolution graphics mode, this command places a dot with x-coordinate
\aexprl\ and y-coordinate \aexpr2\. The color of the dot is determined by
the most recently executed COLOR statement {COLOR=0 if not previously
specified) .
\aexprl\ must be in the range through 39, and \aexpr2\ must be in the
range through 47 or the message
? ILLEGAL QUANTITY ERROR
appears .
An attempt to PLOT while the system is in TEXT mode, or in mixed
GRaphics-plus-text mode with \aexpr2\ in the range 40 to 47, will result in
a character being placed where the colored dot would have appeared. (A
character occupies the space of two low-resolution graphics dots stacked
vertically. )
The command has no visible effect when used in HGR2 High-resolution graphics
mode, even if preceded by a GR command, as the screen is not "locking at"
the low-resolution graphics portion (page one) of memory.
The origin (0,0) for all graphics is in the upper left corner of the
screen.
85
HLIN 1mm i def
HLIN aexprl, aexpr2 AT aexprS
Used In low-resolution GRaphics mode, HLIN draws a line from
(\aexprl\ ,\aexpr3\) to (\aexpr2\,\aexpr3\) . The color Is determined by the
most recently executed COLOR statement.
\aexprl\ and \aexpr2\ must be in the range through 39, and \aexpr3\ must
be In the range through 47, or the message
?ILLEGAL QUANTITY ERROR
appears. \aexprl\ may be greater than, equal to, or less than \aexpr2\.
If HLIN Is used when the system is in TEXT mode, or in mixed
GRaphics-plus-text mode with \aexpr3\ in the range A8 through A7, then a
line of characters will be placed where the line of graphic dots would have
been plotted. (A character occupies the space of two low-resolution dots
stacked vertically.)
The command has no visible effect when used in high-resolution graphics
mode.
Note that the "H" in this command refers to "horizontal" and not
"high-resolution". Except for HLIN and HTAB , the prefix "H" refers to
high-resolution instructions.
VLIN imm & def
VLIN aexprl, aexpr2 AT aexprS
In low-resolution GRaphics mode, draws a vertical line from (\aexprl\,
\aexpr3\) to (\aexpr2\, \aexpr3\). The color is determined by the most
recently executed COLOR statement.
\aexprl\ and \aexpr2\ must be in the range through 47, \aexpr3\ must be in
the range through 39, or the message
?ILLEGAL QUANTITY ERROR
is displayed. \aexprl\ may be greater than, equal to, or less than
\aexpr2\.
If the system is in TE3CT mode when VLIN is used, or in mixed
GRaphics-plus-text with \aexpr2\ in the range 40 through 47, the portion of
the line within the text area will appear as a line of characters, placed
where the graphic dots would have been plotted.
The command has no visible effect when used In high-resolution graphics
mode.
86
SCRN irom t. def
SCRN (aexprl, aexpr2)
In low-resolution GRaphics mode, the function SCRN returns the color code of
the point whose x coordinate is \aexprl\ and whose y coordinate is \aexpr2\.
®
Although low-resolution GRaphics plots points at screen positions (x,y)
where x is in the range through 39 and y is in the range through 47, the
SCRN function accepts both x and y values in the range through 47.
However, if SCRN is used with an x value (\aexprl\) in the range 40 through
47, the number returned gives the color at the point whose x coordinate is
(\aexpr\-40) and whose y coordinate is ( \aexpr2\+16) . If (\aexpr2\+16) is In
the range 39 through 47, in normal mixed GRaphics plus text mode, the number
returned by SCRN is related to the text character at that position In the
text area below the graphics portion of the screen. If (\aexpr2\+16) is in
the range 48 through 63, SCRN returns a number unrelated to anything on the
screen.
In TEXT mode, SCRN returns numbers in the range through 15 whose value is
the
upper four bits, if aexpr2 is odd; or
lower four bits, if aexpr2 is even
of the character at character position
(aexprl+1, INT ( (aexpr2+l ) /2) ) . So the expression
CHR$ (SCRN (X-1 , 2*(Y-1 ) )+l 6*SCRN (X-l , 2*(Y-1 )+l ) )
will return the character at character position (X,Y).
In High-resolution GRaphics mode, SCRN continues to "look at" the
low-resolution GRaphics area, and the number SCRN returns is not related to
the high-resolution display.
SCRN is parsed as a reserved word only if the next non-space character is a
left parenthesis.
imm & del
HGR
No parameters. Sets high-resolution graphics mode (280 by 160) for the
screen, leaving four lines for text at the bottom. The screen is cleared tc
black and page 1 of memory (8K-16K) is displayed. HCOLOR is not changed
by this command. Text screen memory is not affected. Use of the HGR
command leaves the text "window" at full screen , but only the bottom four
text lines are visible below the graphics. The cursor will still be in the
text "window," but may not be visible unless it is moved to one of the
bottom 4 lines.
87
The screen can be converted to full-screen (280 by 192) graphics after
executing HGR with the POKE command
POKE -16302,0
or the use of
POKE 49234,0
which is equivalent. If HGR follows a either of the above POKE commands,
mixed high-resolution graphics-plus-text Is reset.
&^'
If the reserved word HGR is used as the first characters of a variable name,
the HGR may be executed before the
? SYNTAX ERROR
message appears. Thus, executing the statement
HGRIP=4
results In an unexpected trip into high-resolution graphics mode, which may
erase your program.
A very long program which extends above memory location 8192 may be
partially erased when you execute HGR, or it may "write" into your page 1
high-resolution graphics display. In particular, string data is stored at
the top of memory; on small memory systems (16K or 20K) this data may
reside in page 1 of high-resolution graphics. Set HIMEM: 8192 to protect
your program and page 1 of high-resolution graphics.
HGR 2 I mm & def
HGR 2
No parameters. This command sets full-screen high-resolution graphics mode
(280 by 192). The screen is cleared to black, and page 2 of memory
(16K-24K) is displayed. Text screen memory is not affected. This page of
memory (and therefore the command HGR2) is not available if your system
contains less than 24K of memory. On systems that do allow it, using HGR2
instead of HGR maximizes the memory space available for programs.
On 24K systems, set HIMEIl: 16384 to protect page 2 of high-resolution
graphics from your program (especially strings, which are stored at the
top of memory).
If the reserved word HGR2 is used as the first characters in a variable
name, the HGR2 may be executed before the
? SYNTAX ERROR
message is given. When executed, a statement such as
140 IF X > 150 THEN HGR2PIECES = 12
leaves the screen suddenly blank, possibly with the upper reaches of the
program erased.
The command
POKE -16301,0
converts any full-screen graphics mode to mixed graphics-plus-text mode.
When issued after HGR2, however, the four lines of text are taken from page
2_ of text, which is not easily accessible to the user.
88
IICOLOR imm h def
HCOLOR = aexpr
Sets high-resolution graphics color to that specified by the value of
HCOLOR, which must be in the range to 7, inclusive. Color names and their
associated values are
blackl 4 black2
1 green (depends on TV) 5 (depends on TV)
2 blue (depends on TV) 6 (depends on TV)
3 white 1 7 white2
A high-resolution dot plotted with HC0LOR=3 (white) will be blue if the
x-coordinate of the dot is even, green if the x-coordinate is odd, and white
only if both (x,y) and (x+l,y) are plotted. This is due to the way home
TVs work.
HCOLOR Is not changed by HGR, HGR2, or RUN. Until the first HCOLOR
statement is executed, the plotting color for high-resolution graphics is
indeterminate.
If used while in low-resolution GRaphics, HCOLOR does not affect the color
being displayed.
HPLOT inim 4. dcf
HPLOT aexprl, aexpr2
HPLOT TO aexpr3, aexpri
HPLOT aexprl, aexpr2 TO aexpr3, aexpr4 [{TO aexpr, aexpr}]
HPLOT with the first option plots a high-resolution dot whose x-coordlnate
is \aexprl\ and whose y-coordlnate is \aexpr2\. The color of the dot is
determined by the most recently executed HCOLOR statement. The value of
HCOLOR is indeterminate if not previously specified.
The second option causes a line to be plotted from the last dot plotted to
(\aexpr3\, \aexpr4\). The color of this line is determined by the color of
the last dot plotted, even if the value of HCOLOR has been changed since the
previous plotting. If no previous point has been plotted, no line is drawn.
If third option is used, a line from (\aexprl\, \aexpr2\) to (\aexpr3\,
\aexpr4\) is plotted using the color specified by the most recent HCOLOR
command. The plotted line may be extended in the same instruction almost
indefinitely (subject to the screen limits and the 239 character instruction
limit) by extending the instruction with
TO aexpr5, aexpr6 TO aexprn?, aexprS
and so on. The single statement
HPLOT 0,0 TO 279,(3 TO 279,159 TO 0,159 TO 0,0
can plot a rectangular border around all four sides of the high-resolution
screen .
89
®'
HPLOT must be preceeded by HGR or HGR2 to avoid clobbering lots of memory,
including your program and variables.
\aexprl\ and \aexpr3\ must be in the range through 279.
\aexpr2\ and \aexpr4\ must be in the range through 191.
\aexprl\ may be greater than, equal to, or less than \aexpr3\. \aexpr2\ may
be greater than, equal to, or less than \aexpr4\.
An attempt to plot a point whose coordinates exceed these limits causes the
7ILLEGAL QUANTITY ERROR
message. If the screen is in mixed high-resolution graphics plus h lines of
text, then attempts to plot points with y-coordinates in the range 160
through 191 will have no visible effect.
PDL imm & del
PDL (aexpr)
This function returns the current value, from to 255, of the game control
(or PaDdLe) specified by \aexpr\, if \aexpr\ is in the range through 3.
The game control Is a resistance variable from to 150K ohms.
If two game controls are read in consecutive PDL instructions, the reading
from the second game control may be affected by the reading from the first.
To obtain more accurate readings, allow several program lines between PDL
instructions, or place a short delay loop (FOR 1=1 TO 10:NEXT 1) between PDL
instructions.
If \aexpr\ Is negative or greater than 225, the
71LLEGAL QUANTITY ERROR
message is given.
If \aexpr\ is in the range k through 255, the PDL function returns a rather
unpredictable number from to 255, and may cause various side effects, some
of which may disturb program execution.
For instance, if \aexpr\ is in the range 204 to 219, use of the PDL function
is frequently and rather randomly accompanied by a "click" from the
computer's speaker.
If N is In the range 236 through 239, PDL (N ) may result in a
POKE -16540+N,
so that PDL(236) may set GRaphics mode, PDL(237) can set TEXT mode, etc (see
Appendix J).
In addition to reading the settings of 4 variable game controls using PDL,
APPLESOFT can read the state of 3 game buttons (on-off switches) using
various PEEK commands, and can turn on and off 4 game read-outs (TTL
switches) using various POKE commands (see Appendix J).
90
CHAPTER 9
HIGH-RESOLUTION SHAPES
92 How to Create a Shape
97 Saving a Shape Table
97 Using a Shape Table
98 DRAW
98 XDRAW
99 ROT
99 SCALE
99 SHLOAD
HOW TO CREATE A SHAPE TABLE
APPLESOFT has five special commands which allow you to manipulate shapes in
high-resolution graphics: DRAW, XDRAW, ROT, SCALE, and SHLOAD. Before these
APPLESOFT commands can be used, a shape must be defined by a "shape
definition," This shape definition consists of a sequence of plotting
vectors that are stored in a series of bytes in APPLE'S memory. One or more
such shape definitions, with their Index, make up a "shape table" that can
be created from the keyboard and saved on disk or cassette tape for future
use.
Each byte in a shape definition is divided into three sections, and each
section can specify a "plotting vector": whether or not to plot a point, and
also a direction to move (up, down, left, or right). DRAW and XDRAW step
through each byte in the shape definition section by section, from the
definition's first byte through its last byte. When a byte that contains
all zeros is reached, the shape definition is complete.
This is how the three sections A, B and C are arranged within one of the
bytes that make up a shape definition:
Section: C B A
Bit Number: 7 6 5 4 3 2 1
Specifies; DDPDDPDD
Each bit pair DD specifies a direction to move, and each bit P specifies
whether or not to plot a point before moving, as follows:
If DD = W0 move up
= 01 move right If P = don't plot
= 10 move down =1 do plot
= 11 move left
Notice that the last section, C (the two most significant bits), does not
have a P field (by default, P=0), so section C can only specify a move
with out plotting.
Each byte can represent up to three plotting vectors, one in section A, one
in section B, and a third (a move only) in section C.
DRAW and XDRAW process the sections from right to left (least significant
bit to most significant bit: section A, then B, then C). At any section in
the byte, IF ALL THE REMAINING SECTIONS OF THE BYTE CONTAIN ONLY ZEROS, THEN
THOSE SECTIONS ARE IGNORED. Thus, the byte cannot end with a move in
section C of 00 (a move up, without plotting) because that section,
containing only zeros, will be ignored. Similarly, if section C is 00
(ignored), then section B cannot be a move of 000 as that will also be
ignored. And a move of 000 in section A will end your shape definition
unless there is a 1-bit somewhere in section B or C.
92
Suppose you want to draw a shape like this:
First » draw it on graph paper, one
dot per square. Then decide where
to start drawing the shape. Let's
start this one at the center. Next,
draw a path through each point in
the shape, using only 90 degree
angles on the turns:
h^i
— • — • — • —
II I
— • — • — • —
Next, re-draw the shape as a series
of plotting vectors, each one moving
one place up, down, right, or left,
and distinguish the vectors that
plot a point before moving (a dot
marks vectors that plot points).
Now "unwrap" those vectors and write them In a straight line:
u — -tiu -nn- —
Next draw a table like the one In Figure 1, below:
Sec t lor
1 C
B
A
C
B
A
Byte
1
1
010
HI
010
111
2
i
t
100
J00
3
—
i
i
01
100
100
4
•-*-
*-»-
101
101
5
*
m-m-
010
101
6
\
1
110
110
7
—
;
011
110
8
^9
1 11
9
00
000
000
L
This Vector
Cannot Plot
or Move Up
-i
Vector
Code
t
000
001 or 01
i
010 or 10
■^
011 or 11
i
100
♦*■
101
\
110
•*•
HI
-*— Denotes End
of Shape
Definition
Figure 1
[Move
(Only
I Plot
|& Move
For each vector in the line, determine the bit code and place it in the next
available section in the table. If the code will not fit (for example, the
vector in section C can't plot a point), or is a 00 (or 000) at the end of a
byte, then skip that section and go on to the next. When you have finished
coding all your vectors, check your work to make sure it is accurate.
93
Now make another table, as shown in Figure 2, below, and re-copy the vector
codes from the first table. Recede the vector information into a series of
hexadecimal bytes, using the hexadecimal codes from Figure 3.
Bytes
Codes
Section
: C
B
A
Receded
in Hex
Binary
He
Byte
1
1
"0
=
1 2
0000
=
1
1
1
1 1 1
1
=
3 F
0001
=
1
2
1
=
2
0010
=
2
3
1 1
1
=
6 4
0011
=
3
4
1
1 I
1
=
2 D
0100
=
h
5
1
1
1
=
1 5
0101
=
5
6
1
1
1 1
(3
=
3 6
0110
=
6
7
1
1 1 1
7=
1 E
0111
=
7
8
1 I
1
=
7
1000
=
8
9
=
-^-Denotes End
1001
1010
=
9
A
Oi.
anape
~
Hex:
Digit
1
Digit
2
Definition
1011
=
B
1100
=
C
1101
=
D
U10
=
E
Flaure
i 2
1111
=
F
Figure 3
The series of hexadecimal bytes that you arrived at in Figure 2 is the shape
definition. There Is still a little more information you need to provide
before you have a complete shape table. The form of the shape table,
complete with its index , is shown in Figure 4 on the next page.
For this example, your index is easy: there is only one shape definition.
The shape table's starting location, whose address we have called S, must
contain the number of shape definitions (between and 255) in hexadecimal.
In this case, that number is just one. We will place our shape definition
immediately below the index, for simplicity. That means, in this case, the
shape definition will start in byte S+4: the address of shape definition #1,
relative to S, is 4 (00 04, in hexadecimal). Therefore, index byte S+2 must
contain the value 04 and index byte S+3 must contain the value 00. The
completed shape table for this example Is shown in Figure 5 on the next
page.
94
Start=S
Byte S+Q
+1
+2
+3
+4
Index ■
+5
+2n
+2n+l
n (0
to FF) 1
Unused [
Lower
2 Digits
Upper
2 Digits
Lower
2 Digits
Upper
2 Digits
•
Lower
2 Digits
Upper
2 Digits
-Total Number of
Shape Definitions
Dl: Index to First Byte of Shape
Definition //I, Relative to S
D2: Index to First Byte of Shape
Definition #2, Relative to S
Dn; Index to First Byte of Shape
Definition #n. Relative to S
Shape
Definitions
S+DI
S+Dn
First Byte
Last Byte^g
First Byte
Last Byte=
First B y te
Last Byte=g
Shape Definition #1
Shape Definition #2
Shape Definition #n
Figure 4
Start
(Store address
in E8 and E9)
Byte
01
1
00
2
04
3
w
4
12
5
3F
6
20
7
64
8
2D
9
15
A
36
B
IE
C
07
D
00
-Number of Shapes
Index to Shape Definition /^l^
Relative to Start
-First Byte
Shape Definition #1
^-Last Byte
Figure 5
m
You are now ready to type the shape table into APPLE'S memory. First,
choose a starting address. For this example, we'll use hexadecimal address
IDFC. <Note: this address must be less than the highest memory address
available in your system, and not in an area that will be cleared when you
use HGR or HGR2. Location IDFC is just below the high-resolution graphics
page 1, used by HGR.) Press the RESET key to enter the Monitor program, and
type the Starting address for your shape table;
IDFC
if you press the RETURN key now, APPLE will show you the address and the
contents of that address. That is how you examine an address to see if
you have a put the correct number there. If instead you type a colon ( : )
followed by a two-digit hexadecimal number, that number will be stored at
the specified address when you press the RETURN key. Try this:
IDFC return
What does APPLE say the contents of location IDFC are? Now try this:
1DFC:01 return
IDFC return
IDFC- 01
The APPLE now says that the value 01 (hexadecimal) is stored in the location
whose address is IDFC. To store more two-digit hexadecimal numbers in
successive bytes in memory, Just open the first address:
IDFC:
and then type the numbers, separated by spaces:
iDFC:01 m 04 m 12 3F 20 64 2D 15 36 IE 07 00 return
You have just typed in your first complete shape table... not so bad, was it?
To check the information in your shape table, you can examine each byte
separately or simply press the RETURN key repeatedly until all the bytes of
interest (and a few extra, probably) have been displayed:
IDFC return
IDFC- 01
* return
00 04 00
* return
1E00- 12 3F 20 64 2D 15 36 IE
* return
1E08- 07 00 DF IE 23 00 00 FF
If your shape table looks correct, all that remains is to store the starting
address of the shape table where APPLESOFT can find it (this is done
automatically when you use SHLOAD to get a table from cassette tape).
APPLESOFT looks for the four hex digits of the table's starting address in
hex locations E8 (lower two digits) and E9 (upper two digits). For our
table's starting address of ID FC, this would do the trick:
E8:FC ID return
To protect your shape table from being accidentally erased by your APPLESOFT
program, it might also be a good idea to set HIMEM: (in hex locations 73 and
74) to the table's starting address:
73:FC ID
This too is done automatically when you use SHLOAD to get the table from
cassette tape.
96
SAVING A SHAPE TABLE
To save your shape table on tape, you need to know three things:
1) Starting address of the table (IDFC, in our example)
2) Last address of the table (1E09, in our example)
3) Difference between 2) and I) (000D, in our example)
Item 3, the difference between the last address and the first address of the
table, must be stored in hex locations (lower two digits) and 1 (upper two
digits):
0:HD 00 return
Now you can "Write" (store on cassette) first the table length that is
stored in locations to 1 , and then the shape table itself that is stored
in locations Starting Address through Last Address:
0. IW 1DFC.1E09W
Don't press the RETURN key until you have put a cassette In your tape
recorder, rewound it, and started it recording (press PLAY and RECORD
simultaneously). Now press the computer's RETURN key.
To use the tape, rewind it, start it playing (press PLAY), and (in
APPLESOFT, now) type
SHLOAD return
You should hear one "beep" when the table's length has been read
successfully, and another "beep" when the table itself has been read-
USING A SHAPE TABLE
You are now ready to write an APPLESOFT program using the shape-table
commands DRAW, XDRAW, ROT and SCALE.
Here's a sample APPLESOFT program that will print our defined shape, rotate
it 16 degrees, and then repeat, each repetition larger than the one before.
It} HGR
20 HCOLOR = 3
30 FOR R = 1 TO 50
40 ROT = R
50 SCALE = R
60 DRAW 1 AT 139, 79
70 NEXT R
To see a single "square", add a line
65 END
To pause and then erase each square after it is drawn add these lines:
63 FOR 1=0 TO 1000: NEXT 1
65 XDRAW 1 AT 139, 79
97
DRAW imra & def
DRAW aexprl AT aexpr2, aexpr3
DRAW aexprl
DRAW with the first option draws a shape in high-resolution graphics
starting at the point whose x-coordinate is \aexpr2\ and whose y-coordinate
is \aexpr3\. The shape drawn is the \aexprl\th shape definition In the
shape table previously loaded using the SHLOAD command (or a shape table may
be typed into the APPLE'S memory In hexadecimal code, using the Monitor
program) .
\aexprl\ must be In the range through n, where n Is the number (from
through 255) of shape definitions given In byte of the shape table.
\aexpr2\ must be in the range through 278. \aexpr3\ in the range
through 191. If any of these ranges is exceeded, the message
? ILLEGAL QUANTITY ERROR
will be displayed.
The color, rotation and scale of the shape to be drawn must have been
specified before DRAW is executed.
The second option is similar to the first, but draws the specified shape
starting at the last point plotted by the most recently executed HPLOT,
DRAW, or XDRAW command.
w
If Issued when there Is no shape table in the computer, may cause the system
to "hang." To recover, use reset Ctrl C return. May also draw random
"shapes" all over the high-resolution graphics areas of memory, possibly
destroying your program, even if you are not in graphics mode.
XDRAW iiiim & def
XDRAW aexprl [AT aexpr2, aexpr3]
This command Is the same as DRAW, except that the color used to draw the
shape is the complement of the color already existing at each point
plotted. These pairs of colors are complements:
Black and White
Blue and Green
The purpose of XDRAW is to provide an easy way to erase: if you XDRAW a
shape, and then 3(DRAW It again, you'll erase the shape without erasing the
background.
m
See cautionary remarks for DRAW.
98
ROT inim 6. dc-f
ROT = aexpr
Sets angular rotation for shape to be drawn by DRAW or XDRAW. The amount of
rotation is specified by \aexpr\, which must be between to 255.
ROT=(il will cause the shape to be DRAWn oriented jusC as it was defined,
R0T=16 will cause the shape to be DRAWn rotated 90 degrees clockwise, ROT=32
will cause the shape to be DRAWn rotated 180 degrees clockwise, etc. The
process repeats starting at ROT=64. For SCALE=1, only 4 rotation values are
recognized (0,16,32,48); for SCALE=2, 8 rotations are recognized, etc.
Unrecognized rotation values will cause the shape to be DRAWn with the
orientation of the next smaller (usually) recognized rotation.
ROT parses as a reserved word only if the next non-space character is the
replacement sign ( = ).
SCALE imiD 6. def
Sets scale size for shape to be drawn by DRAW or XDRAW to factor from 1
(point for point reproduction of the shape definition) to 255 (each vector
extended 255 times) as specified by \aexpr\. NOTE: SCALE=0 is maxiiri'im
size and not a single point.
SCALE parses as a reserved word only if the next non-space character is the
replacement sign ( = ).
SHLUAU iram 4. def
SHLOAD
Loads a shape table from cassette tape. Shape table is loaded just below
HIMEM: and HIMEM: is set to just below the shape table to protect It. The
shape table's starting address is given to APPLESOFT'S shape-drawing
routines automatically. If a second shape table is loaded, replacing the
first table, HIMEM: should be reset prior to loading to avoid wasting
memory. Shape table tapes are prepared using the instructions at the
beginning of this chapter.
On 16K systems, HGR clears the top 8K of memory, from location 8192 to
location 16383. To force SHLOAD to put the shape table below page 1 of
high— resolution graphics, set HIMEM; 8192 before executing SHLOAD. On 24K
systems, do not use HGR 2 (which clears memory from location 16384 to
99
location 24575), or else set HIMEM: 16384 before SHLOAD and do not use HGR.
If you are sure there is enough safe memory above location 24575 to hold
your shape table, there is nothing to worry about.
Only reset can interrupt SHLOAD. If the reserved word SHLOAD begins a
variable name, the reserved-word command may be executed before any
?SYNTAX ERROR is given. The statement
SHLOADER =59
hangs the system, while APPLESOFT waits indefinitely for a program from the
cassette recorder. Use reset Ctrl C to regain control of the computer.
100
CHAPTER 1 U
SOME MATH FUNCTIONS
1^2 The built-in functions SIN, COS, TAN,
ATN, INT, RND, SGN, ABS, SQR, EXP, LOG
103 Derived Functions
BUILT-IN FUNCTIONS
All functions may be used wherever an expression of the same type may be
used. They may be used in either immediate or deferred execution. Here are
brief descriptions of some of APPLESOFT'S arithmetic functions. Other
functions are described in sections dealing with similar instructions.
SIN (aexpr)
Returns the sine of \aexpr\ radians.
COS (aexpr)
Returns the cosine of \aexpr\ radians.
lAN faexpr )
Returns the tangent of \aexpr\ radians.
ATK (aexpr)
Returns the arctangent, in radians, of \aexpr\. The angle returned is in
the range -pi/2 through +pi/2 radians.
l;,r (n> ;-;|.r )
Returns the largest integer less than or equal to \aexpr\.
RND (aoxpr)
Returns a random real number greater than or equal to and less than 1.
If \aexpr\ is greater than zero, RND(aexpr) generates a new random number
each time it is used.
If \aexpr\ is less than zero, RND (aexpr) generates the same random number
each time It is used with the same \aexpr\, as if from a permanent random
number table built into the APPLE. If a particular negative argument Is
used to generate a random number, then subsequent random numbers generated
with positive arguments will follow the same sequence each time. A
different random sequence is initialized by each different negative
argument. The primary reason for using a negative argument for RND is to
initialize (or "seed") a repeatable sequence of random numbers. This is
particularly helpful in debugging programs that use RND.
If \aGxpr\ Is zero, RND(aexpr) returns the most recent previous random
number generated (CLEAR and NEW do not affect this). Sometimes this Is
easier than assigning the last random number to a variable in order to save
it.
SGN (aexpr)
Returns -1 if \aexpr\<0, returns if \aexpr\=0, and returns 1 if \aexpr\>0.
ABS (aexpr)
Returns the absolute value of \aexpr\ ie. \aexpr\ If \aexpr\>=0, and
-\aexpr\ if \aexpr\<0.
SQR (aexpr)
Returns the positive square root. This is a special implementation that
executes more quickly than ~.5
102
EXP (ncxpr^
Raises e (to 6 places, e=2. 718289) to the indicated power, \aexpr\.
LOG (aexpr '
Returns the natural logarithm of \aexpr\.
DERIVED FUNCTIONS
The following functions, while not intrinsic to APPLESOFT BASIC, can be
calculated using the existing BASIC functions and can be easily implemented
by using Che DEF FN function.
SECANT:
SEC(X) = 1/C0S(X)
COSECANT:
CSC(X) = 1/SIM(X)
COTANGENT:
COT(X) = 1/TAN(X)
INVERSE SINE:
ARCSIN(X) = ATN(X/SQR(-X*X+1))
INVERSE COSINE:
ARCCOS(X) = -ATN(X/SQR(-X*X+1))+1. 5 7
INVERSE SECANT:
ARCSEC(X) = ATN(SQR(XAX-1))+(SGN(X)-1)*1.5/
INVERSE COSECANT:
ARCCSC(X) = ATN(1/SQR(X*X-1 ))+(SGN(X)-l)*1.57
INVERSE COTANGENT:
ARCCOT(X) = -ATN(X) + 1.5 7(38
HYPERBOLIC SINE:
SINH(X) = (EXP(X)-EXP(-X))/2
103
HYPERBOLIC COSINE:
COSH(X) = (EXP(X)+EXP(-X))/2
HYPERBOLIC TANGENT:
TANH(X) = -EXP(-X)/(EXP(X)+EXP(-X))*2+1
HYPERBOLIC SECANT:
SECH(X) = 2/(EXP(X)+EXP(-X))
HYPERBOLIC COSECANT:
CSCH(X) = 2/(EXP{X)-EXP(-X))
HYPERBOLIC COTANGENT:
COTH(X) = EXP(-X)/(EXP(X)-EXP(-X))*2+1
INVERSE HYPERBOLIC SINE:
ARGSINH(X) = LOG(X+SqR(X*X+l))
INVERSE HYPERBOLIC COSINE:
ARGCOSH(X) = L0G(X+SQR(X*X-1))
INVERSE HYPERBOLIC TANGENT:
ARGTANH(X) = LOG ( ( 1+X) / ( 1-X) ) /2
INVERSE HYPERBOLIC SECANT:
ARGSECH(X) = L0G((SQR(-X*X+1)+I)/X
INVERSE HYPERBOLIC COSECANT:
ARGCSCH(X) = L0G(SGN(X)*SQR(X*X+1)+1)/X
INVERSE HYPERBOLIC COTANGENT:
ARGCOTH(X) = L0G((X+l)/(X-l))/2
A MOD B
MOD(A) = INT((A/B-INT(A/B))*B+.05)*SGN(A/B)
104
m
Appendix A;
110
Appendix B:
115
Appendix C:
U8
Appendix D:
120
Appendix E:
121
Appendix F:
122
Appendix G:
12A
Appendix H:
126
Appendix I:
128
Appendix J:
138
Appendix K:
14(3
Appendix L:
1A2
Appendix M:
144
Appendix N:
15(3
Appendix 0:
Getting APPLESOFT BASIC up
Program Editing
Error Messages
Space Savers
Speeding Up Your Program
Decimal Tokens for Keywords
Reserved Words in APPLESOFT
Converting BASIC Programs to APPLESOFT
Memory Map (see also page 137)
PEEKS, POKES and CALLs
ASCII Character Codes
APPLESOFT Zero Page Usage
Differences Between APPLESOFT and Integer BASIC
Alphabetic Glossary of Syntactic Definitions
and Abbreviations
Summary of APPLESOFT Commands
Appendix A: Getting APPLESOFT BASIC Up
And Running
APPLE Computer Inc. offers two versions of the BASIC programming language.
Integer BASIC, described in the APPLE II BASIC Programming Manual , is a
very fast BASIC suited for many applications, especially in education, game
playing, and graphics. The other version of BASIC is called "APPLESOFT" and
is better suited for most business and scientific applications.
APPLESOFT BASIC is available in two versions. Firmware APPLESOFT comes with
APPLESOFT in ROM on a printed circuit card (APPLE Part Number A2B0009X)
which plugs directly into the APPLE II. With this option, the flick of a
switch and two key-strokes start the APPLE II running in APPLESOFT. Aside
from this convenience, having APPLESOFT in ROM saves about 10K of memory and
saves much time loading the language in at every use, from a cassette tape.
The main body of this manual assumes you have the firmware APPLESOFT card.
If you are using the cassette version of APPLESOFT, see PART II of
this appendix for special instructions and notes on where your APPLESOFT
differs from that described in the rest of this manual.
Note; in this manual, the word reset means to press the key marked RESET,
return means to press the key marked RETURN, and Ctrl B means to type B
while holding down the key marked CTRL .
AM IMPORTANT NOTE :
One of the functions of the prompt character, besides PROMPTing you for
input to the computer, is to identify at a glance which language the
computer is programmed to respond to at that time. For Instance, up till
now you have seen two prompt characters:
* for the >Ionltor program (when you press RESET)
> for APPLE Integer BASIC (the normal Integer BASIC)
Now we Introduce a third prompt character:
] for APPLESOFT floating-point BASIC.
By simply looking at this prompt character, you can easily tell (if you
forget) which language the computer is in.
PART 1: FIRMWARE APPLESOFT
INSTALLING THE FIRMWARE APPLESOFT BOARD
The firmware APPLESOFT card simply plugs into a socket inside the APPLE II.
Care must be exercised, however, so follow these instructions exactly:
1) Turn the APPLE off: very Important to prevent damaging the computer,
2) Remove the cover from the APPLE II. This is done by pulling up on the
cover at the rear edge (the edge farthest from the keyboard) until the two
corner fasteners pop apart. Do not continue to lift the rear edge, but
slide the cover backward until it comes free.
106
3) Inside the APPLE II, across the rear of Che circuit board, there is a
row of eight long, narrow sockets called "slots." The leftmost one (looking
at the computer from the keyboard end) is slot #0; the rightmost one is slot
#7. Hold the APPLESOFT card so that Its switch is toward the back of the
computer; insert the "fingers" portion of the card into the leftmost slot,
slot //0. The fingers will enter the slot with some friction, and will then
seat firmly- The APPLESOFT card must be placed in slot #0.
4) The switch on the back of the APPLESOFT card should protrude part way
through the slot on the back of the APPLE II.
5) Replace the APPLE'S cover: first slide the front edge into place, then
press down on the two rear corners until they pop into place.
7) Now turn on the APPLE II.
USING THE FIRMWARE APPLESOFT BOARD
With the APPLESOFT card's switch In the downward position, the APPLE II
will begin operating in Integer BASIC when you use reset ctrl B (this
manual's way of saying: press the key marked RESET, then hold down the key
marked CTRL while typing B). You will see the prompt character >, which
indicates Integer BASIC.
With the switch in the upward position, reset Ctrl B will bring up
APPLESOFT BASIC, instead of Integer BASIC. The prompt character ] tells you
you're in APPLESOFT.
When using the Disk Operating System, the computer will automatically choose
Integer BASIC or APPLESOFT, as required. It does not matter in which
position the switch is set.
You can also change from Integer BASIC to APPLESOFT, or vice versa,
without: operating the switch on the firmware card. To put the computer
into APPLESOFT, use
reset C080 return
Ctrl B return
and to put the computer into Integer BASIC, use
reset C081 return
Ctrl B return
ANOTHER IMPORTANT NOTE :
Sometime you may accidently hit RESET and find yourself in the Monitor, as
shown by the * prompt character. You may be able to return to APPLESOFT
BASIC, with APPLESOFT and your program intact, by typing
Ctrl C return
107
PART 2: CASSETTE TAPE APPLESOFT
APPLESOFT II BASIC is provided on cassette tape, at no charge, with each
APPLE II. APPLESOFT BASIC loaded from cassette tape occupies approximately
l(i)K bytes of memory, thus a computer with 16K bytes or more memory is
required to use the cassette version of APPLESOFT BASIC .
GETTING STARTED WITH CASSETTE TAPE APPLESOFT
Use the following procedure to load APPLESOFT from your cassette unit:
1) Start up Integer BASIC by typing reset Ctrl B. If you are unfamiliar
with this procedure, see your APPLE Integer BASIC Programming Manual. You
will know you are in Integer BASIC when you see the prompt character >
displayed on the TV screen, followed by the blinking square "cursor."
2) Place the APPLESOFT tape (Part Number A2T0004) in your cassette recorder
and rewind the tape to the beginning.
3) Type LOAD
A) Press the recorder's "play" lever to start the tape playing.
5) Press the key marked RETURN on the APPLE II keyboard. When you do this
the blinking cursor will disappear. After 5 to 20 seconds the APPLE II will
beep, to signal that the tape's information has started to go into the
computer. After about 1-1/2 minutes, there will be another beep and the
prompt character > followed by a cursor will reappear.
6) Stop the tape recorder and rewind the tape. APPLESOFT is now in the
computer.
7) Type RU'N and press the key marked RETURN. The screen will display the
copyright notice for APPLESOFT II and APPLESOFT'S prompt character, ] .
Sometime you may accidentally hit the R^SET key and find yourself in the
Monitor program, as shown by the prompt character * . You may be able to
return to APPLESOFT, with your progran and APPLESOFT itself still intact, by
typing
0C return
If this does not work, you will have to re-load APPLESOFT from cassette
tape .
Typing Ctrl C or Ctrl E from the Monitor program will transfer you to APPLE
Integer BASIC; this will erase APPLESOFT,
In this manual, reset means to press the key marked RESET, return means to
press the key marked RETURN, and Ctrl B means to type B while holding down
the key marked CTRL .
108
DIFFERENCES BETWEEN FIRMWARE APPLESOFT AND CASSETTE APPLESOFT
APPLESOFT on cassette tape (Part Number A2T(}004) does not work exactly the
same as does the firmware version of APPLESOFT that resides in ROM on a
plug-in printed circuit card (Part Number A2B0C)09X). Most of this manual
describes the firmware version of APPLESOFT. The following comments point
out how cassette APPLESOFT differs from firmware APPLESOFT.
Because cassette APPLESOFT occupies approximately 10K of memory (and the
computer uses another 2K), cassette APPLESOFT cannot be used in APPLEs with
less than 16K of memory. With cassette APPLESOFT loaded, the lowest memory
location available to the user is approximately 12300. Firmware APPLESOFT
does not reside in RAM memory, so it can be used (without high-resolution
graphics) in smaller systems.
fff^
HGR is not available in cassette APPLESOFT. The HGR command clears "page
1" of graphics memory (8K. to 16K) for high-resolution graphics. Since
cassette APPLESOFT partly occupies this portion of memory, attempting to use
HGR will erase APPLESOFT, and may erase your program. The HGR2 command can
be used both in the ROM and in the cassette versions of APPLESOFT, but is
only available If your APPLE contains at least 24K of memory. Therefore, in
a system with less than 24K of memory, cassette APPLESOFT does not offer
high-resolution graphics.
The command
POKE -16301,0
converts any full-screen graphics mode to mixed graphics-plus-text mode.
When issued after HGR2, however, the four lines of text are taken from page
2 of text memory. In the cassette version of APPLESOFT, APPLESOFT itself
occupies page 2 of text memory, so that mixed high-resolution
graphics-plus-text is not available.
With Integer BASIC, and with APPLESOFT on the firmware card, you can return
to your program after an accidental or intentional press of the RESET key by
using Ctrl C return. To accomplish the same thing with cassette APPLESOFT,
you must use 0G return (type 0, then type G and press the RETURN key). If
you are using cassette APPLESOFT, reset Ctrl C return will reinstate Integer
BASIC as your programming language; this will erase APPLESOFT.
In short, everywhere this manual says to use
reset ctrl C return
cassette APPLESOFT users should use
reset 0G return
instead.
Where the manual says to use
reset ctrl B return
you can do the same, but you will then have to reload APPLESOFT from tape.
In cassette APPLESOFT, use CALL 11246 (instead of CALL 62450) to clear the
HGR2 screen to black. Use CALL 11250 (instead of CALL 62454) to clear the
HGR2 screen to the HCOLOR last HPLOTted. If executed before you issue the
HGR2 command the first time, these CALLs may erase APPLESOFT.
109
Appendix B: Program Editing
Most ordinary humans make mistakes occasionally. . .especially when writing
computer programs. To facilitate correcting these "oversights" APPLE has
incorporated a unique set of editing features into APPLESOFT BASIC.
To make use of them you will first need to familiarize yourself with the
functions of four special keys on the APPLE II keyboard. They are the
escape key, marked ESC, the repeat key, marked REPT, and the left- and
right-arrow keys, which are marked with a left arrow and a right arrow.
ESC
The escape key { ESC ) is the leftmost key in the second row from the top.
It is ALWAYS used with another key (such as A, B, C or D keys) in this
way: push and release ESC, and then push and release A, for
instance. . * . alternately .
This operation or sequence of the ESC key and then another key is written as
"escape A". There are four escape functions used for editing:
escape A moves cursor to the right
escape B moves cursor to the left
escape C moves cursor down
escape D moves cursor up
Using the escape key and the desired key, the cursor may be moved to any
location on the screen without affecting anything that is already displayed
there, and without affecting anything in memory.
RIGHT-ARROW KEY
The right-arrow key moves the cursor to the right. It is the most
time-saving key on the keyboard because it not only moves the cursor, but IT
COPIES ALL CHARACTERS AND SYMBOLS IT "MOVES ACROSS" INTO APPLE IT'S MEMORY,
JUST AS IF YOU HAD TYPED THEM IN FROM THE KEYBOARD YOURSELF. The TV display
is not changed when you use the right-arrow key.
LEFT-ARROW KEY
The left-arrow key moves the cursor to the left. Each time the cursor moves
to the left, ONE CHARACTER IS ERASED FROM THE PROGRAM LINE VJHICH YOU ARE
CURRENTLY TYPING, regardless of what the cursor is moving over. The TV
display is not changed when you use the left-arrow key. Usually the
left-arrow key cannot be used to move the cursor into the leftmost column:
use escape B to do this.
110
REFT
The REPT key is used with another character key on the keyboard. It causes
a character to be repeated as long as both the character's key and the REPT
key are held down.
Now you're ready to use these editing functions to save time when making
changes or corrections to your prograin. Here are a few examples of how to
use then.
Example 1 — Fixing Typos
Suppose you've entered a program by typing it in, and when you RUN it, the
computer prints SYNTAX ERR and stops, presenting you with the ] prompt and
the flashing cursor.
Enter the following program and RUN it. Note that "PRIMT" and "PREGRAM" are
mis-spelled on purpose. Below is approximately how it will look on your TV
display:
]10 PRIHT "THIS IS A PREGRAM"
]2g GOTO 19
? SYNTAX ERR IN 10
]l
Now type the word LIST and press return:
J LIST
19 PRIMT"THIS IS A PREGRAM"
29 GOTO 10 '
11
To move the cursor up to the beginning of line 10, type escape D three times
and then escape B. Note: it is important to use escape B to place the
cursor over the very first digit in the line number. The TV screen will
now look like this:
]LIST
V PRIMT"THIS IS A PREGKjVI"
20 GOTO 10
111
Now press the right-arrow key 6 times to move the cursor on to the letter M
in "PRIMT". Remember, as the right-arrow key moves the cursor over a
character on the screen, that character Is copied into APPLE'S memory Just
as if you had typed it in from the keyboard. The TV display will no« look
like this:
]LIST
10 PRlfl"THIS IS A PREGRAM"
2(3 GOTO 10
Now type the letter N to correct the spelling of "PRIMT", then copy (using
the right-arrow key and the repeat key) over to the letter E In "PREGRAM".
The TV screen will now look like this:
]LIST
10 PRINT"THIS IS A PRiGRAM"
20 GOTO 10
If you typed the right-arrow key too many times by holding down the repeat
key too long, use the left-arrow key to backspace back to the letter E.
Now, type the letter to correct "PREGRAM" and copy using the right-arrow
key to the end of line 10. Finally, store the new line in program memory by
pressing the RETURN key.
Type LIST to see your corrected program;
ILIST
1
10 PRINT "THIS IS A PROGRAM"
20 GOTO 10
Now RUN the program (use Ctrl C to stop the program):
IRUH
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
THIS IS A PROGRAM
BREAK IN 10
112
Example 2 — Inserting Text into an Existing Line
In the previous example, suppose you had wanted to insert a TAB (10) conmand
after the PRINT in line 10, Here's how you could do it. First LIST the
line to be changed:
]LIST 10
10 PRINT "THIS IS A PROGRAII"
II
Type escape D's and an escape B until the cursor is on the very first
character of the line to be changed; then use the right-arrow and repeat
keys to copy over to the first quotation mark. (Remember, a character is
not copied into memory until you use the right-arrow key to move the cursor
f roro that character on to the next-) Your TV display should now look like
this:
ILIST 10
10 PRINT ItHIS IS A PROGRAM"
1
Now type another escape D to move the cursor to the empty line just above
the current line and the display will look like:
JLIST 10
I
10 PRINT "THIS IS A PROGRAM"
I
Type the characters to be inserted which, in this case, are TAB(10);. Your
TV display should now look like this:
ILIST 10
TAB(10);I
10 PRINT "THIS IS A PROGRAM"
)
Type an escape C to move the cursor down one line so that the display looks
like this:
ILIST 10
TAB (10);
10 PRINT "THIS ISiA PROGRAM"
113
Now backspace back to the first quotation mark using escape B (using the
left-arrow key here would delete the characters you have just typed). The
TV display will now look like this:
]L1ST 10
TAB (10);
10 PRINT ItHIS is a program"
From here, copy the rest of the line using the right-arrow and repeat keys
until the display looks like this:
LIST 10
TAB(l(il);
PRINT "THIS IS A PROGRAM"
]
Depress the RETURN key and type LIST to get the following:
]tIST
]
10 PRINT TAB( 1(J);"TH1S IS A PR
OGRAM"
20 GOTO 10
II
Where you wish to avoid copying extra spaces which the LIST format
Introduces into the middle of lines (such as those between the R and the O
of PROGRAM, in the example above), use escape A. Escape A moves the cursor
to the right without copying characters. This can be especially useful
when copying PRINT, INPUT and REM statements, where APPLESOFT does not
ignore extra spaces.
Remember, using the escape keys, one may copy and edit text that is
displayed anywhere on the TV display.
114
Appendix C: Error Message
After ah error occurs, BASIC returns to command level as indicated by the ]
prompt character and a flashing cursor. Variable values and the program
text remain intact, but the program can not be continued and all GOSUB and
FOR loop counters are set to 0.
To avoid this interruption in a running program, the ONERR GOTO statement
can be used, in conjunction with an error-handling routine.
When an error occurs in an immediate-execution statement, no line number Is
printed.
Format of error messages:
Immediate-execution Statement ?XX ERROR
Deferred-execution Statement ?XX ERROR IN YY
In both of the above examples, "XX" is the name of the specific error. "yY"
is Che line number of the deferred-execution statement where the error
occurred. Errors in a deferred-execution statement are not detected until
that statement is executed-
The following are the possible error codes and their meanings.
CAN'T CONTINUE
Attempt to continue a program when none existed, or after an error occurred,
or after a line was deleted from or added to a program.
DIVISION BY ZERO
Dividing by zero is an error.
ILLEGAL DIRECT
You cannot use an INPUT, DEF FN, GET or DATA statement as an
immediate-execution command.
ILLEGAL QUANTITY
The parameter passed to a math or string function was out of range.
QUANTITY errors can occur due to:
a) a negative array SUBSCRIPT (e.g., LET A(-1)=0)
b) using LOG with a negative or zero argument
c) using SQR with a negative argument
d) A~B with A negative and B not an integer
e) use of MID$, LEFTS, RIGHT$, WAIT, PEEK, POKE, TAB, SPG,
ON... GOTO, or any of the graphics functions with an
improper argument*
115
NEXT WITHOUT FOR
The variable in a NEXT statement did not correspond to the variable in a FOR
statement which was still in effect, or a nameless NEXT did correspond to
any FOR which was still in effect.
OUT OF DATA
A READ statement was executed but ail of the DATA statements in the program
had already been read. The program tried to read too much data or
insufficient data was Included in the program.
OUT OF MEMORY
Any of the following can cause this error: program too large; too many
variables; FOR loops nested more than 10 levels deep; GOSUB's nested more
than 2A levels deep; too complicated an expression; parentheses nested more
than 36 levels deep; attempt to set LOMEM: too high; attempt to set LOMEM:
lower than present value; attempt to set HIMEM: too low.
FORMULA TOO COMPLEX
More than two statements of the form IF "XX" THEN were executed.
OVERFLOW
The result of a calculation was too large to be represented in BASIC'S
number format. If an underflow occurs, zero is given as the result and
execution continues without any error message being printed.
REDIM'D ARRAY
After an array was dimensioned, another dimension statement for the same
array was encountered. This error often occurs if an array has been given
the default dimension 1(3 because a statement like A(I)=3 is followed later
in the program by a DIM A(100). This error message can prove useful if you
wish to discover on what program line a certain array was dimensioned: Just
insert a dimension statement for that array in the first line, RUN the
program, and APPLESOFT will tell you where the original dimension statement
is.
RETURN WITHOUT GOSUB
A RETURN statement was encountered without a corresponding GOSUB statement
being executed.
STRING TOO LONG
Attempt was made by use of the concatenation operator to create a string
more than 255 characters long.
116
BAD SUBSCRIPT
An attempt was made to reference an array element which is outside the
dimensions of the array. This error can occur if the wrong number of
dimensions are used in an array reference; for instance, LET A(1,I,1)=Z when
A has been dimensioned using DIM A(2,23.
SYNTAX ERROR
Missing parenthesis in an expression, illegal character in a line, Incorrect
punctuation, etc.
TYPE MISMATCH
The left-hand side of an assignment statement was a numeric variable and the
right-hand side was a string, or vice versa; or a function which expected a
string argument was given a numeric one or vice versa.
UNDEF'D STATEMENT
An attempt was made to GOTO, GOSUB or THEN to a statement line number which
does not exist.
UNDEF'D FUNCTION
Reference was made to a user-defined fuction which had never been defined.
117
Appendix D: Space Savers
SPACE HINTS
In order to make your program fit into less memory space, the following
hints may be useful. However, the first two space-savers should be
considered only when faced with serious space limitations. Serious
programmers often keep two versions of their programs: one expanded and
heavily documented (with REM's), the other "crunched" to use the minimum
memory space.
1) Use multiple statements per line. There is a small amount of overhead
(5 bytes) associated with each line in the program. Two of these five bytes
contain the line number of the line in binary. This means that no matter
how many digits you have in your line number (minimum line number is 0,
maximum is 65529), it takes the same number of bytes (two). Putting as many
statements as possible on each line will cut down on the number of bytes
used by your program. (A single line can include up to 239 characters.)
Note: combining many statements on one line makes editing and other changes
very difficult. It also makes a program very difficult to read and
understand, not only for others but also for you when you return to the
program later on.
2) Delete all REM statements. Each REM statement uses at least one byte
plus the number of bytes in the common text. For instance, the statement
130 REM THIS IS A COMMENT uses up 2A bytes of memory. In the statement
140 X=X+Y: REM UPDATE SUM
the REM uses 12 bytes of memory including the colon before the REM.
Note: like multiple-line programs, a program without detailed REM statements
is very difficult to read and understand, not only for others but also for
you when you return to the program later on.
3) Use integer instead of real arrays wherever possible (see Storage
Allocation Information, later in this appendix).
4) Use variables instead of constants. Suppose you use the constant
3. I4I59 ten times in your program. If you insert a statement
10 P=3. 14159
in the program, and use P instead of 3.14159 each time it is needed, you
will save 40 bytes. This will also result in a speed improvement.
5) A program need not end with an END; so, an END statement at the end of a
program may be deleted.
6) Re-use the same variables. If you have a variable T which is used to
hold a temporary result in one part of the program and you need a temporary
variable later in your program, use it again. Or, if you are asking the
computer's user to give a YES or NO answer to two different questions at two
different times during the execution pf the program, use the same temporary
variable A$ to store the reply.
118
7) Use GOSUB's to execute sections of program statements that perform
identical actions.
8) Use the zero elements of matrices; for Instance, A(0), B{0,X).
9) When A$="CAT" is reassigned to A$="DOG" the old string "CAT" Is not
erased from memory. Using a statement of the form
X = FRE(0)
periodically within your program will cause APPIESOFT to "house clean" old
strings from the top of memory.
STORAGE ALLOCATION INFORMATION
Simple (non-array) real, Integer, or string variables like V, V%, or VS use
7 bytes. Real variables use 2 bytes for the variable name and 5 bytes for
the value (1 exponent, 4 mantissa). Integer variables use 2 bytes for the
variable name, two bytes for the value, and have 0's in the remaining three
bytes. String variables use 2 bytes for the variable name, 1 byte for the
length of the string, 2 bytes for a pointer to the location of the string in
memory, and have 0's in the remaining 2 bytes. See page 137 for map.
Real array variables use a minimum of 12 bytes: two bytes for the variable
name, two for the size of the array, one for the number of dimensions, two
for the size of each dimension, and five bytes for each array element.
Integer array variables use only 2 bytes for each array element. String
array variables use 3 bytes for each array element: one for length, tv;o for
a pointer. See page 137 for map.
String variables, whether simple or array, use one byte of memory for each
character in the string. The strings themselves are located in order of
occurence in the program, beginning at HIHEM:.
When a new function is defined by a DEF statement, 6 bytes are used to store
the pointer Co the definition.
Reserved words such as FOR, GOTO or NOT, and the names of the intrinsic
functions such as COS, INT and SIRS take up only one byte of program
storage. All other characters in programs use one byte of program storage
each.
V/hen a program is being executed, space Is dynamically allocated on the
stack as follows:
1) Each active FOR... NEXT loop uses 16 bytes.
2) Each active GOSUB (one that has not RETURNed yet) uses 6 bytes.
3) Each parenthesis encountered In an expression uses 4 bytes and each
temporary result calculated in an expression uses 12 bytes.
119
Appendix E: Speeding Up Your Program
The hints below should Improve the execution time of your BASIC programs.
Note that some of these hints are the same as those used to decrease the
memory space used by your programs. This means that in many cases you can
increase the speed of your programs at the same time you improve the
efficiency of their memory use.
1) THIS IS PROBABIY THE MOST IMPORTANT SPEED HINT BY A FACTOR OF 1(3: use
variables instead ot constants. It takes more time to convert a constant to
its floating point (real number) representation than it does to fetch the
value of a simple or array variable. This is especially important within
FOR... NEXT loops or other code that is executed repeatedly.
2) Variables which are encountered first during the execution of a BASIC
program are allocated at the start of the variable table. This means that a
statement such as
5 A = 3:B=A:C=A
will place A first, B second, and C third in the variable table (assuming
line 5 Is the first statement executed In the program). Later in the
program, when BASIC finds a reference to the variable A, it will search only
one entry in the variable table to find A, two entries to find B and three
entries to find C, etc.
3) Use NEXT statements without the index variable. NEXT is somewhat faster
than NEXT I because no check, is made to see If the variable specified in the
NEXT is the same as the variable in the most recent still-active FOR
statement.
4) During program execution, when APPLESOFT encounters a new line reference
such as "GOTO 10W' it scans the entire user program starting at the lowest
line until it finds the referenced line number (1000, in this example).
Therefore, frequently-referenced lines should be placed as early in the
program as possible.
120
Appendix F: Decimal Tokens For Keywords
decimal
token
keyword
128
END
129
FOR
13(9
NEXT
131
DATA
132
INPUT
133
DEL
134
DIM
135
READ
136
GR
137
TEXT
138
PR#
139
1K#
140
CALL
141
PLOT
142
HLIN
143
VLIN
144
HGR2
145
HGR
146
HCOL0R =
147
HPLOT
148
DRAW
149
XDRAW
150
HTAB
151
HOME
152
ROT =
153
SCALE=
154
SHLOAD
155
TRACE
156
HOTRACE
157
NORMAL
158
INVERSE
159
FLASH
160
COLOR =
161
POP
162
VTAB
163
HIMEM:
decimal
token
keyword
164
LOMEM :
165
ON ERR
166
RESUME
167
RECALL
168
STORE
169
SPEED=
170
LET
171
GOTO
172
RUN
173
IF
174
RESTORE
175
&
176
GOSUB
177
RETURN
178
REM
179
STOP
180
ON
181
WAIT
182
LOAD
183
SAVE
184
DEF
185
POKE
186
PRINT
187
CONT
188
LIST
189
CLEAR
190
GET
191
NEW
192
TAB(
193
TO
194
FN
195
SPC(
196
THEN
197
AT
198
NOT
199
STEP
decimal
token
keyword
200
+
201
-
202
A
203
/
204
*"■
205
AND
206
OR
207
>
208
=
209
<
210
SGN
211
INT
212
ABS
213
USR
214
FRE
215
SCRN(
216
PDL
217
POS
218
SQR
219
RKD
220
LOG
221
EXP
222
COS
223
SIN
224
TAN
225
ATN
226
PEEK
227
LEN
228
STR$
229
VAL
2 30
ASC
231
CHR$
232
LEFTS
233
RIGHTS
234
MID?
121
Appendix G: Reserved Words in APPLESOFT
ABS
AND
ASC
AT
ATN
CALL
CHR$
CLEAR
COLOR =
CONT
COS
DATA
DEF
DEL
DIM
DRAW
END
EXP
FLASH
FN
FOR
FRE
GET
GOSUB
GOTO
GR
HCOLOR=
HGR
HGR 2
HIMEM:
HLIN
HOME
HPLOT
1¥
im
INPUT
INT
INVERSE
LEFT$
LEN
LET
LIST
LOAD
LOG
LOMEM:
MID§
SEW
NEXT
NORMAL
NOT
NOTRACE
OS
ONERR
OR
EDI
PEEK
PLOT
POKE
POP
POS
PRINT
READ
RECALL
END
REM
ROT =
RESTORE
RUN
RESUME
RETURN
RIGHT $
SAW
SCALE=
SPEED=
SCRN (
SQR
SGN
STEP
SHLOAD
STOP
SIN
STORE
SPC(
STR$
TABC
TAH
TEXT
THEN
TO
TRACE
K-SR
VAL
VEIN
VTAB
WAIT
XPLOT
XDRAW
PR#
APPLESOFT "tokenlzes" these reserved words: each word takes up only one byte
of program storage. All other characters in program storage use up one byte
of program storage each* See Appendix F for reserved'Word tokens.
122
(^
The ampersand ( & ) is intended for the computer's internal use only; it is
not a proper APPLESOFT command. This symbol, when executed as an
instructions causes an unconditional jump to location S3F5. Use reset Ctrl
C return to recover.
XPLOT is a reserved word that does not correspond to a current APPLESOFT
command ■
Some reserved words are recognized by APPLESOFT only in certain contexts.
COLOR, HCOLOR, SCALE, SPEED, and ROT
parse as reserved words only if the next non-space
character Is the replacement sign, = . This is of
little benefit in the case of COLOR and HCOLOR, as
the included reserved word OR prevents their use in
variable names anyway.
SCRH, SPC and TAB
parse as reserved words only if the next non-space
character is a left parenthesis, ( .
HIMEM: must have Its colon ( : ) to be parsed as a reserved
word.
LOHEM: also requires a colon ( : ) if it is to be parsed as
a reserved word.
All! IS parsed as reserved word only if there is no space
between the T and the N. If a space occurs between the
T and the N, the reserved word AT is parsed, instead
of ATN.
TO is parsed as a reserved word unless preceded by an
A and there is a space between the T and the 0. If a
space occurs between the T and the 0, the reserved word
AT is parsed instead of TO.
Sometimes parentheses can be used to get around reserved words:
100 FOR A = LOFT OR CAT TO 15
LISTS as 100 FOR A = LOF TO RC AT TO 15
but 100 FOR A = (LOFT) OR (CAT) TO 15
LISTS as 100 FOR A = (LOFT) OR (C AT ) TO 15
123
Appendix H: Converting BASIC Programs to APPLESOFT
Though implementations of BASIC on different computers are in many ways
similar, there are some incompatibilities which you should watch for if you
are planning to convert BASIC programs to APPLESOFT.
1) Array (matrix) subscripts. Some BASICs use "[" and "]" to denote array
subscripts. APPLESOFT uses "(" and ")".
2) Strings. A number of BASICs force you to dimension (declare) the length
of strings before you use them. You should remove all dimension statements
of this type from the program. In some of these BASICs, a declaration of
the form DIM AS(I,J) declares a string array of J elements each of which has
a length I. Convert DIM statements of this type to equivalent ones In
APPLESOFT: DIM A5 ( J ) .
APPLESOFT uses "+" for string concatenation, not "," or "&".
APPLESOFT uses LEFTS, RIGHTS and MIDS to take substrings of strings. Other
BASICs use AS(1) to access the Ith character of the string AS, and AS(I,J)
to take a substring of A$ from character position I to character position J.
Convert as follows:
OLD NEW
A$(I) tlID$(AS,I,l)
AS(I,J) MIDS(A$,I,J-1 + 1)
This assumes that the reference to a substring of AS is in an expression or
is on the right side of an assignment. If the reference to AS is on the
left-hand side of an assignment, and X$ is the string expression used to
replace characters in AS, convert as follows:
OLD NEW
A$(I)=X$ A$=LEFTS(A$,I-l)+X$-fMID$(AS,I + l)
A$(I,J)=XS AS=LEFT$(A$,I-1)+XS-H«DS(AS,J+1)
124
3) Some BASICs allow "multiple assignment" statements of the form
500 LET B = C = (jl
This statement would set both tlie variables B and C to zero.
In APPLESOFT BASIC this has an entirely different effect. All the ='s to
the right of the first one would be interpreted as logical comparison
operators. This would set the variable B to -1 if C equaled 0. If C did
not equal 0, B would be set to 0.
The easiest way to convert statements like this one is to rewrite them as
follows :
500 C = : B = C
4) Some BASICs use "/" instead of ":" to delimit multiple statements per
line. Change each "/" to ";" In the program.
5) Programs which use the MAT functions available in some BASICs will have
to be rewritten using FOR... NEXT loops to perform the appropriate
operations.
125
Appendix I: Memory Map
MEMORY RANGE
0. IFF
2(3(3. 2FF
3(?(3. 3FF
4(?(3. 7FF
8(2(3. 2FFF
3FFF
3(30(3. XXX
3.5FFF
0(3(3(2. CFFF
D(30(3.DFFF
3.F7FF
E(?(2l2.F7FF
F8(3(3.FFFF
DESCRIPTION
Program work space; not available to user.
Keyboard character buffer.
Available to user for short machine
language programs.
Screen display area for page 1 text or color graphics.
In cassette tape version, the
APPLESOFT BASIC intepreter.
If firmware APPLESOFT (Part number A2B(3(309X) installed,
user program. and variable space, where XXX is raaximum
RAM memory to be used by APPLESOFT. This Is either
total system RAM memory, or less if the user is
reserving part of high memory for machine language
routines or high-resolution screen buffers.
Firmware APPLESOFT only: high-resolution
graphics display page 1.
Cassette tape APPLESOFT II;
user program and variables where XXX
is maximum available RAM memory to be
used by APPLESOFT. This is either total
system RAM memory, or less if the user is
reserving part of high memory for machine
language routines or page 2 high-resolution graphics.
High-resolution graphics display page 2.
Hardware 1/0 Addresses.
Future ROM expansion.
APPLESOFT II firmware version, with select
switch "ON" (up).
APPLE Integer BASIC.
APPLE System Monitor.
126
DIAGRAM OF APPLESOFT PROGRAM MEMORY MAP
cassette
version
$3(301
$2FFF
$8fll
pointer
Disk Operating System
(if disk is being used)
$73 - $74 (HIMEM: )
HIMEM: is automatically set to
the maximum RAM memory location
in the system, unless set by
the user.
STRINGS
$6F - $75
FREE SPACE
including the high-resolution
graphics' screen buffers
(with cassette APPLESOFT,
only, page 2 is available).
NOTE; string space may fill
with old data and run over
the high-resolution screens
or machine programs. To
initiate house-cleaning and
and avoid this problem. Insert
X=FRE(0) in your program.
$6D - S6E
NUMERIC AND STRItlG-POINTER
ARRAYS (see page 137)
$6E - $6C
SIMPLE VARIABLES (see page 137)
$69 - S6A (LOMEM: )
$Ar - $B0
PROGRAM
$67 - $68
APPLESOFT
firmware
version
$801
F7FF
D000
127
Appendix J: PEEKs, POKEs, and CALLs
Here are a few of the special features of APPLESOFT that you can use by
means of PEEK, POKE, or CALL commands. Notice that some of them duplicate
the effects of other commands in APPLESOFT.
Simple switching actions are usually address dependent: any command
involving that address will have the same effect on the switch. Thus, the
example may be
POKE -16304,
but you will get the same effect by POKElng that address with any number
from through 255, or by PEEKing that address:
X = PEEK(-16304)
This does not apply to commands in which you must POKE the required address
with a specific value which sets a margin or moves the cursor to a
specific place.
SEHING THE TEXT WINDOW
The first four POKE commands, with example line numbers 10, 20, 30, and 40,
are used to set the size of the "window" in which text is shown and scrolled
on your TV screen. These set, respectively, the left margin, line width,
top margin and bottom margin of the window.
Setting the text window does not clear the remainder of the screen, and does
not move the cursor into the text window (use HOME, or HTAB and VTAB). The
VTAB command Ignores the text window entirely: text printed above the window
appears normally, while text printed below the window appears all on one
line. HTAB can also move the cursor outside the window, but only long
enough to print one character there.
A change In line width goes Into effect immediately, but a change in the
left margin Is not detected until the cursor tries to "return" to the left
margin.
Text displayed on the TV screen is merely a special map of a particular
portion of APPLE'S memory (text page 1). The TV screen always "looks at"
this same portion of memory for its text, and sees what the APPLE has
"written" there. When you change the text window, you are telling the APPLE
where in memory to "write" its text. This works fine, as long as you
specify a portion of memory that is within the usual text area. But if
you set the left margin, say, to 255 (the maximum should be 40, since the
screen is 40 print-positions wide), you are telling the APPLE to "write"
text far beyond the usual memory area reserved for text. This memory is not
shown on the screen, and may contain parts of your program or even
information necessary to APPLESOFT itself. To keep your program and
APPLESOFT safe, just refrain from setting the text window beyond the
confines of the 40-character by 24-llne screen.
128
10 POKE 32, L
Sets left margin of TV display to value specified by L, in the range from
through 39, where is leftmost position. Tliis change is not effected until
the cursor attempts to "return" to the left margin.
®
The width of the window Is not chang ed by this command: this means
that the right margin will be moved by the same amount you move the left
margin. To preserve your program and APPLESOFT, first reduce tlie window
width appropriately; then change the left margin.
20 POKE 33, W
Sets the width (number of characters per line) of TV display to the value
specified by W, in the range from L through 40.
Do not set W to zero: POKE 33, bombs APPLESOFT.
>S^
If U is less than 33, the PRINT command's third tab-field may print
characters outside the window.
30 POKE 34, T
Sets top margin of TV display to value specified by T, in the range from
through 23 where is the top line on the screen. A POKE 34, A will not
allow text to be printed in the first four lines of the screen. Do not set
the top margin of the window (T) lower than the bottom margin (B, below).
40 POKE 35, B
Sets bottom margin of TV display to value specified by B, in the range from
through 24 where 24 is the bottom line on the screen. Do not set the
bottom margin of the window (B) higher than the top margin (T, above).
OTHER COMMANDS AFFECTING TEXT, THE TEXT WINDOW,
AND THE KEYBOARD
45 CALL -936
Clears all characters inside the text window, and moves the cursor to the
window's top leftmost printing position. This is the same as esc @ return
(Escape {<>) and the command HOME.
129
50 CALL -958
Clears all characters inside of text window from current cursor position to
bottom margin. Characters above the cursor, and characters to the left of
the cursor in its printing line will not be affected. This is the same as
esc F (Escape F).
If the cursor is above the text window, clears from the cursor to the right,
left and bottom margins as if the top margin were above the cursor. It Is
not usually desirable to use this command if the cursor is below the bottom
margin of the text window: usually the bottom line of the text window Is
cleared, along with one line of text— window width at the cursor position.
60 CALL -868
Clears current line from cursor to right margin. This Is the same as esc E
(Escape E).
70 CALL -922
Issues a line feed. This is the same as Ctrl J (Control J).
80 CALL -912
Scrolls text up one line; i.e., moves each line of text within the defined
window up one position. Old top line is lost; old second line becomes line
one; bottom line is now blank. Characters outside defined window are not
affected.
90 X = PEEK(-1638A)
Reads keyboard. If X>127 then a key has been pressed, and X is ASCII value
of key pressed with bit 7 set (one). This Is useful in long programs, in
which the computer checks to see if the user wants to interrupt with new
data without stopping program execution.
IW POKE -16368,0
Resets keyboard strobe so that next character may be read in. This should
be done Immediately after reading the keyboard.
COMMANDS THAT DEAL WITH THE CURSOR
110 CH = PEEK(36)
Reads back the current horizontal position of the cursor and sets variable
CH equal to It. CH will be in the range from through 39 and is the
130
cursor's position relative to the text window's left-hand margin, as set by
POKE 32, L. Thus, if Che left margin was set by POKE 32,5 then the leftmost
character in the window is at the 6th printing-position from the left edge
of the screen and if PEEK (36) returned a value of 5 then the cursor was at
the 11th printing-position from the left edge of the screen and at the 6th
printing position from the left margin of the text window. (It sounds
confusing at first, because the leftmost position is position zero, not 1.)
This is identical to the POS (X) function. (See next example.)
120 POKE 36, CH
Moves the cursor to a position that is CH+1 printing-positions from the left
margin of the text window. (Example: POKE 36,0 will cause next character to
be printed at the left margin of the window.) If the left margin of the
window was set at 6 (POKE 32,6) and you wanted to provide a character three
positions from left edge of the screen, then the window's left margin must
be changed prior to PRINTlng. CH must be less than or equal to the window
width as set by POKE 22, W and must be greater than or equal to zero. Like
HTAB, this command can move the cursor beyond the right margin of the text
window, but only long enough to print one character.
130 CV = PEEK(37)
Reads the current vertical position of the cursor and sets CV equal to it.
CV is the absolute vertical position of the cursor and is not referenced to
the top or bottom margins of the text window. Thus CV-0 is top line on
screen and CV=23 is bottom.
140 POKE 37, CV
Moves the cursor to the absolute vertical position specified by CV.
the topmost line and 23 is the bottom line.
COMMANDS AFFECTING GRAPHICS
For purposes of displaying text and graphics, the APPLE'S memory is divided
into 4 areas: text pages 1 and 2, and high-resolution pages 1 and 2.
1) Text page 1 Is the usual menory area for all text and low-resolution
graphics, as used by the TEXT and GR commands.
2) Text page 2 lies just above text page 1 in memory. It is not easily
accessible to the user. Like text page 1, Information stored in text page 2
can be interpreted either as text or as low-resolution graphics, or both.
3) High-resolution graphics page 1 resides in APPLE's memory from 8k to
16k. This is the area used by the HGR command. If text is shown with this
page, it comes from text page 1.
4) High-resolution graphics page 2 resides in APPLE's memory from 16k
to 24k. This is the area used by the HGR2 command. If text Is shown with
this page, it comes from text page 2.
131
To use the different graphics and text modes, you can use APPLESOFT'S text
and graphics commands or you can operate these 4 different switches. As
with many of Che switches discussed here, a PEEK or POKE to one address sets
the switch one way, and a PEEK or POKE to a second address sets the switch
the other way. In brief, these 4 switches choose between:
1) Text display
and Graphics display, high- or low-resolution
2) Page 1 of text or high-resolution
and Page 2 of text or high-resolution
3) Text page 1 or 2 for graphics
and High-resolution page 1 or 2 for graphics
4) Full-screen high- or low-resolution graphics
and Mixed high- or low-resolution graphics+text
(POKE
-16303
0)
(POKE
-16304
0)
(POKE
-16300
0)
(POKE
-16299
0)
(POKE
-16298
0)
(POKE
-16297
0)
(POKE
-16302
0)
(POKE
-16301
0)
150 POKE -16304,0
Switches display mode from text to color graphics without clearing the
graphics screen to black. Depending on the settings of the other 3
switches, the graphics mode switched to may be low-resolution or
high-resolution, from page 1 or 2, and in mixed graphics+text or full-screen
graphics.
Similar APPLESOFT commands: The GR command switches to page 1
low-resolution, mixed-screen graphics+text, and clears graphics screen to
black. The HGR command switches to page 1 high-resolution, mixed-screen
graphics+text, and clears graphics screen to black. The HGR2 command
switches to page 2 high-resolution, full-screen graphics and clears entire
screen to black.
160 POKE -16303,0
Switches display mode from any color graphics display to all text mode
without resetting scrolling window. Depending on the setting of the Page
1/Page 2 switch, the text page switched to may be either text page 1 or text
page 2.
The TEXT command switches to all text mode, but in addition chooses text
page 1, resets scrolling window to maximum and positions cursor in lower
left-hand corner of TV display.
170 POKE -16302,0
Switches from mixed-screen graphics+text to full-screen graphics-
Depending on the settings of the other switches, this may appear as text, as
low-resolution graphics on a 40 by 48 grid, or as high-resolution graphics
on a 278 by 192 grid.
132
18(J POKE -163(31,0
Switches from full-screen graphics to mixed-screen graphics+text mode, with
four 4(3-character lines of text at bottom of screen.
Depending on the settings of the other switches, the upper portion of the
screen may show text, low-resolution graphics on a 40 by 40 grid, or
high-resolution graphics on a 278 by 160 grid. Both portions of the screen
display will come from the same page number <1 or 2).
184 POKE -16300,0
Switches from Page 2 to Page 1, without clearing the screen or moving the
cursor. Necessary when you go into Integer BASIC from APPLESOFT; otherwise
you may still be "looking" at page 2 of memory.
Depending on the settings of the other switches, this can cause the display
to change from high-resolution graphics page 2 to high-resolution graphics
page 1, from low-resolution graphics page 2 to low-resolution graphics page
1, or from text page 2 to text page 1.
186 POKE -16299,0
Switches from Page 1 to Page 2, without clearing the screen or moving the
cursor.
Depending on the settings of the other switches, this can cause the display
to change from high-resolution graphics page 1 to high-resolution graphics
page 2, from low-resolution graphics page 1 to low-resolution graphics page
2, or from text page 1 to text page 2.
190 POKE -16298,0
Switches the page for graphics from a high-resolution graphics page to the
same page of text, without clearing the screen. Necessary when you go into
Integer BASIC from APPLESOFT; otherwise the Integer BASIC GR instruction may
Incorrectly show you the high-resolution page.
Depending on the settings of the other switches, this may cause the display
to change from high-resolution graphics page 1 to low-resolution graphics
page 1, from high-resolution graphics page 2 to low-resolution graphics page
2, or (in text mode) may cause no change in the display.
195 POKE -16297,0
Switches the page for graphics from a text page to the corresponding page of
high-resolution, without clearing the screen.
Depending on the settings of the other switches, this may cause the display
to change from low-resolution graphics page 1 to high-resolution graphics
page 1, from low-resolution graphics page 2 to high-resolution graphics page
2, or (in text mode) may cause no change in the display.
133
2QQ CALL -1994
Clears the upper 20 lines of text page 1 to reversed (? signs. If you are in
page 1 low-resolution graphics mode, this clears the upper 40 lines of the
graphics screen to black. Has no effect on text page 2 or on
high-resolution graphics.
235 CALL -1998
Clears entire text page 1 to reversed @ signs. If you are in page 1
low-resolution full-screen graphics mode, this clears the entire screen to
black. Has no effect on text page 2 or on high-resolution graphics.
200 CALL 62450
Clears current high-resolution screen (APPLESOFT remembers which screen you
used last, regardless of the switch settings) to black.
210 CALL 62454
Clears current high-resolution screen (APPLESOFT remembers which screen you
used last, regardless of Che switch settings) to the HCOLOR most recently
HPLOTted. Must be preceded by a plot.
COMMANDS DEALING WITH GAME CONTROLS
AND SPEAKER
220 X = PEEK(-16336)
Toggles speaker once: produces a "click" from speaker.
225 X = PEEK(-16352)
Toggles cassette-output once: produces a "click" on a cassette recording.
230 X = PEEK(-16287)
Reads pushbutton switch on game control #0. If X>127 then this button is
being pressed.
240 X = PEEK(-16286)
Same as above but pushbutton on game control #1.
250 X = PEEK(-16285)
Game control #2 pushbutton.
134
260 POKE -16296, 1
Set game control "annunciator" output #0 (Game I/O connector, pin 15) to TTL
open-collector high (3.5 volts). This is the "off" condition.
270 POKE -16295,0
Set game control output //0 to TTL low ( .3 volts). This is the "on"
condition: maxiiruTn current 1.6 milliamperes .
280 POKE -16294,1
Set game control output #1 (Game I/O connector, pin 14) to TTL high (3.5
volts) .
290 POKE -16293,0
Set game control output #1 to TTL low (0.3 volts).
300 POKE -16292,1
Set game control output #2 (Game I/O connector, pin 13) to TTL high (3.5
volts) .
310 POKE -16291,0
Set game control output #2 to TTL low (0.3 volts).
320 POKE -16290, 1
Set game control output #3 (Game I/O connector, pin 12) to TTL high (3.5
volts) .
330 POKE -16289,0
Set game control output to TTL low (0.3 volts).
COMMANDS RELATED TO ERRORS
340 X = PEEK (218) + PEEK (219) * 256
This statement sets X equal to the line number of the statement where an
error occurred if an ONERRGOTO statement has been executed.
135
350 IF PEEK {216)>127 THEN GOTO 20(()0
If bit 7 at memory location 222 (ERRFLG) has been set true, then an
ONERRGOTO statement has been encountered.
360 POKE 216,0
Clears ERRFLG so that normal error messages will occur.
370 Y = PEEK (222)
Sets variable Y to a code that described type of error that caused an
ONERRGOTO jump to occur. Error types are described belovj:
Y VALUE
ERROR TYPE ENCOUNTERED
16
22
hi
53
69
77
90
107
120
133
163
176
191
224
254
255
NEXT without FOR
Syntax
RETURN without GOSUB
Out of DATA
Illegal Quantity
Overflow
Out of Memory
Undefined Statenient
Bad Subscript
Redimensioned Array
Division by Zero
Type Mismatch
String Too Long
Formula Too Complex
Undefined Function
Bad Response to an INPUT Statement
Ctrl C Interrupt Attempted
380 POKE 768, 104
POKE 772, 223
POKE 776, 72
POKE 769, 168
POKE 773, 154
POi;£ 777, 96
POKE 770, 104
POKE 774, 72
POKE 771, 166
POKE 7 75, 152
Establishes a machine-language subroutine at location 768, which can be used
in an error-handling routine. Clears up some ONERR GOTO problems with PRINT
and ?OUT OF MEllORY ERROR messages. Use the command CALL 768 in the
error-handling routine.
136
POINTERS
S69-$6A
APPLESOFT VARIABLE MAPS
REAL
NAME (pos)
1st
byte
(pos)
2nd
byte
exponent
1
byte
niantissa
El.S
byte
TTiantissa
mantissa
mantissa
l.S
byte
SIMPLE VARIABLES
INTEGER
NAME (neg) 1st byte
(neg) 2nd byte
high byte
low byte
i\RRAY VARIABLES
STRING POINTERS
NAME
(neg) 1st byte
(pos) 2nd byte
length
address
address
1 byte
low byte
high byte
INTEGER
3TRIKG POINTERS
$6B-S6C
$6D-$6E
NAME (pos
) 1st
byte
(pos
) 2nd
byte
OFFSET pointer
to
next variable:
add
to address of
this
variable
name
low
byte
high
byte
NO. OF DIMENSIONS |
one
byte
SIZE Nth
DIMENSION 1
high
byte
low
byte
1
SIZE 1st
DIMENSION 1
high
byte
low
byte
REAL ((3,0
,..,0) 1
exponent
1
byte
mantissa
in. s
byte
mantissa
mantissa
mantissa
I.s
byte
1
REAL (M,N
,..,") 1
exponent
1
byte
Eiantissa
n.s
byte
mantissa
mantissa
nantlssa
I.s
byte
NAME (neg) 1st byte
(neg) 2nd byte
OFFSET pointer to
next variable: add
to address of this
variable name
low byte
high byte
NO. OF DIMEIiSIONS
one byte
SIZE Nth DIMENSION
high byte
low byte
SIZE 1st DIMENSION
high byte
low byte
INTEGERS (0,0,.., 0)
high byte
low byte
INTEGERS ([J,tl,..,N)
high byte
low byte
NAME (neg) 1st byte
(pos) 2nd byte
OFFSET pointer to
next variable: add
to address of this
variable name
low byte
high byte
NO. OF DIMENSIONS
one byte
SIZE Nth DIMENSION
high byte
low byte
SIZE 1st DIMENSION
high byte
low byte
STRING $
length
address
address
1 byte
low byte
high byte
STRING$ (N,N,..,N)
length 1 byte
address lovi byte
address high byte
Strings are stored in order of entry, from HIMEM; down. String table points
to first character of each string, at the bottom of the string in memory.
As strings are changed, new pointing addresses are written; when available
memory is used up, house-cleaning deletes all abandoned strings.
(House-cleaning Is forced by a FRE(X)).
All arrays are stored with the right-most index ascending slowest; e.g., the
numbers In the array A%(1,1) where A%(0,0)=0, A4(l,0)=l, A%(0,1)=2,
A3^(l,l)-3 ^Jould be found in memory in proper sequence.
137
Appendix K: ASCII Character Codes
DEC = ASCII decimal code
HEX = ASCII hexadecimal code
CHAR = ASCII character name
n/a = not accessible directly from the APPLE II keyboard
DEC HEX CHAR WHAT TO TYPE
DEC HEX CHAR WHAT TO TYPE
00
NULL
Ctrl
(3
1
01
SOH
Ctrl
A
2
02
SIX
Ctrl
B
3
03
ETX
Ctrl
C
4
04
ET
Ctrl
D
5
05
ENQ
Ctrl
E
6
06
ACK
Ctrl
F
7
07
BEL
Ctrl
G
8
08
BS
Ctrl
H or —
9
09
HT
Ctrl
I
10
0A
LF
Ctrl
J
U
0B
VT
Ctrl
K
12
00
FF
Ctrl
L
13
0D
CR
Ctrl
M or RETURN
lA
0E
SO
Ctrl
N
15
0F
SI
Ctrl
16
10
DLE
Ctrl
P
17
11
DCl
Ctrl
Q
18
12
DC 2
Ctrl
R
19
13
DC 3
Ctrl
S
20
14
DC 4
Ctrl
T
21
15
NAK
Ctrl
u or ^
22
16
SYN
Ctrl
V
23
17
ETB
Ctrl
W
24
18
CAN
Ctrl
X
25
19
EM
Ctrl
Y
26
lA
SUB
Ctrl
Z
27
IB
ESCAPE
ESC
28
IC
FS
n/a
29
ID
GS
Ctrl
shift-M
30
IE
RS
Ctrl
-~
31
IF
US
n/a
32
20
SI
33
21
I
34
22
M
35
23
//
36
24
$
37
25
%
38
26
&
39
27
'
40
28
(
41
29
)
42
2A
*
43
2B
+
44
2C
,
45
2D
-
46
2E
,
47
2F
/
48
30
49
31
1
50
32
2
51
33
3
52
34
4
53
35
5
54
36
6
55
37
7
56
38
8
57
39
9
58
3A
:
59
3B
;
60
3C
<
61
3D
=
62
3E
>
63
3F
7
SPACE
138
DEC HEX CHAR WHAT TO TYPE
64
40
(?
@
65
41
A
A
66
42
B
B
67
43
C
C
68
44
D
D
69
45
E
E
n
46
F
F
71
47
G
G
72
48
H
H
73
49
I
I
74
4A
J
J
75
4B
K
K
76
4C
L
L
77
4D
M
M
78
4E
N
N
79
4F
80
50
P
P
81
51
Q
Q
82
52
R
R
83
53
S
S
84
54
T
T
85
55
U
U
86
56
V
V
87
57
W
w
88
58
X
X
89
59
Y
Y
90
5A
Z
Z
91
5B
[
n/a
92
50
\
n/a
93
5D
]
] (shift-M)
94
5E
-
-
95
5F
n/a
ASCII codes in the range 96 through 255 will generate characters on the
APPLE which repeat those in the list above (first those in column 2, then
the entire series again). Although CHRS(65) returns an A and CHR$(193) also
returns an A, APPLESOFT does not recognize the two as the same character
when using string logical operators, and a printer connected to your APPLE
would print them differently.
139
Appendix L: APPLESOFT Zero Page Usage
LOCATION (s)
(in hex) USE
$0-$5 Jump Instructions to continue in APPLESOFT.
(reset 0G return for APPLESOFT is equivalent to
reset Ctrl C return for Integer BASIC, )
$A-$C Location for USR function's junp instruction.
See USR function description.
$D-SI7 General purpose counters/flags for APPLESOFT.
$20-S4F APPLE II systen monitor reserved locations.
$50-S61 General purpose pointers for APPLESOFT.
$62— $66 Result of last mul tiply /divide.
$67-$68 Pointer to beginning of program. Normally
set to S0801 for ROM version, or $3001
for RAM (cassette tape) version.
$69-$6A Pointer to start of simple variable space. Also
points to the end of the progran plus 1 or 2,
unless changed with the LOMEM: statement.
$6B-S6C Pointer to beginning of array space.
$6D-$6E Pointer to end of numeric storage in use.
$6F-$70 Pointer to start of string storage. Strings are
stored from here to the end of memory.
$71-572 General pointer.
$73-S74 Highest location in memory available to APPLESOFT
plus one. Upon initial entry to APPLESOFT, is
set to the highest RAM memory location available.
$75-576 Current line number of line being executed.
S77-578 "Old line number". Set up by a Ctrl C, STOP
or END statement. Gives line number at which
execution was interrupted.
$79-$7A "Old text pointer". Points to location in memory
for statement to be executed next.
$7B-57C Current line number from which DATA is being READ.
140
$7D-$7E Points to absolute location in memory from which
DATA is being READ.
$7F-?80 Pointer to current source of INPUT. Set to $201
during an INPUT statement. During a READ
statement is set to the DATA in the program
it is READing from.
S81-$82 Holds the last-used variable's name.
$83-$84 Pointer to the last-used variable's value.
$85-S9C General usage.
$9D-$A3 Main floating point accumulator.
$A4 General use In floating point math routines.
$A5-$AB Secondary floating point accumulator.
SAC-$AE General usage flags/pointers.
$AF-B0 Pointer to end of program ( not changed by LOHEM:
SB1-§C8 CHRGET routine. APPLESOFT calls here
everytime it wants another character.
5B8-$B9 Pointer to last character obtained through
the CHRGET routine.
SC9-$CD Random number.
$D0-$D5 High-resolution graphics scratch pointers.
$D8-$DF OMERR pointers/scratch.
$E0-$E2 High-resolution graphics X and Y coordinates.
$E4 High-resolution graphics color byte.
SE5-SE7 General use for high-resolution graphics.
$E8-$E9 Pointer to beginning of shape table.
$EA Collision counter for high-resolution graphics.
$F0-$F3 General use flags.
SF4-$F8 ONERR pointers.
\m
Appendix M: Differences Between
APPLESOFT and Integer BASIC
DIFFERENCES BETWEEN COMMANDS
These commands are available in APPLESOFT, but not in Integer BASIC:
ATN
CHR$
COS
DATA
DEF FN
DRAW
EXP
FLASH
FN
FRE
GET
HCOLOR
HGR
HGR 2 HIMEM:
HOME HPL(
INT
INVERSE
LEFT$
LOG
LOMEM:
MID$
NORMAL
ON. ..GOSUB
ON... GOTO
ONERR GOTO
POS
READ
RECALL
RESTORE RESUME
RIGHT$ ROT
SCALE
SHLOAD
SIN SPC
SPEED SQR
STORE
STR$
TAN
USR
VAL
WAIT
XDRAW
These commands are available In Integer BASIC, but not in APPLESOFT:
AUTO
DSP
MAN MOD
These are named differently In the languages:
Integer BASIC
CLR
CON
TAB
GOTO X*10+100
GOSUB X*10(}+H200
CALL -936
POKE 50,127
POKE 50,255
X
#
APPLESOFT
CLEAR
CONT
HTAB (Note: APPLESOFT also has a TAB)
ON X GOTO 100
ON X GOSUB 10
HOME (or CALL
INVERSE
NORMAL
X% ( % indicates integer variable
<> or ><
APPLESOFT also has
Z0, 110, 120
3, 1100, 1200
-936)
OTHER DIFFERENCES
In Integer BASIC, the correctness of a statements's syntax is checked when
the statement is stored in the computer's memory (when you press the RETURN
key). In APPLESOFT, such checking is done when a statement is executed.
142
GOTO and GOSUB must be followed by a line number In APPLESOFT; Integer BASIC
allows an arithmetic variable or expression.
Real variables and constants ("floating point" numbers with decimal ponts
and/or exponents) are permitted in APPLESOFT but not in Integer BASIC.
In APPLESOFT, only the first two characters in a variable name are
significant (e.g., GOOD and GOUGE are recognized as the same variable by
APPLESOFT). In Integer BASIC, all characters in a variable name are
significant .
String operations are differently defined in the two languages. Both
strings and arrays must be DIMensioned in Integer BASIC; only arrays are
DIMensioned in APPLESOFT.
In APPLESOFT, arrays may be multi-dimensional; in Integer BASIC, arrays are
limited to one dimension.
APPLESOFT sets all array elements to zero on executing RUN, CLEAR, or reset
Ctrl B return. In Integer BASIC, the user's program must set all array
elements to zero.
When the assertion in an Integer BASIC IF... THEN... statement evaluates as
zero (false), only the THEN portion of the statement is ignored. In
APPLESOFT, all statements following a THEN and on the same line will be
ignored when the IF assertion evaluates as zero (false): program execution
jumps to the next numbered program line.
In APPLESOFT, the TRACE command displays the line number of each individual
instruction on a multiple-instruction program line, not just the first
instruction, as in Integer BASIC.
In APPLESOFT, the CALL, PEEK, and POKE commands may use the true range of
memory location addresses (0 through 65335). In Integer BASIC, locations
with addresses greater than 32767 must be referred to by their
two's-complement negative values (location 32768 is called -32767-1; 32769
is called -32767; 3277(2 Is called -32766; etc.).
END in a program which stops on the highest line number is optional in
APPLESOFT, but required in all cases to avoid an error message in Integer
BASIC.
NEXT must be followed by a variable name in Integer BASIC; a variable name
is optional in APPLESOFT.
In Integer BASIC, the syntax of the INPUT statement is
INPUT [string,] <var,}
If var Is an avar, then INPUT prints a ? with or without the optional
string. If var is a svar, then no ? is printed, whether or not the optional
string is present. In APPLESOFT, the syntax of the INPUT statement is
INPUT [string;] {var,}
If the optional string is omitted, APPLESOFT prints a ?; if the optional
string is present, no ? is printed.
143
Appendix N: Alphabetic Glossary of Syntactic
Definitions and Abbreviations
See Chapter 2 for a logical (as opposed to alphabetic) presentation of these
definitions. The symbol := means "is at least partially defined as*"
alphanumeric character
:= letter|dlgit
alop
:= arithmetic logical operator
: = AND |0R I = I > I < I X I <> 1 <= I =< I >= I =>
NOT is not included here on purpose.
a op
:= arithmetic operator
:= +i-i*i/r
avar
:= arithmetic variable
: = name [ name%
All simple variables occupy 7 bytes in memory, 2 bytes for
the name and 5 bytes for the real or integer value.
:= avar subscript
In arrays, reals occupy 5 bytes, integers 2 bytes.
aexpr
arithmetic expression
avar | real | Integer
avar subscript
(aexpr)
If parentheses are nested more than 36 levels deep, the
?OUT OF MEMORY ERROR occurs.
:= [+I-INOT] aexpr
Unary NOT appears here, along with unary + and -
:= aexpr op aexpr
:= sexpr slop sexpr
character
;= letter Idlgit [special
Ctrl
:= hold down the key marked "CTRL" while the
following named key is pressed
def
:= deferred-execution mode
delimi ter
:= ~I(I)IH-I + I*n<l>l/M;|:
A name does not have to be separated from a preceding
or following key word by any of these delimiters.
digit
:= 1|2|3|4|5|6|7|8|9|0
144
-esc,
:= a press of the Escape key, marked "ESC"
expr
:= expression
: = aexpr | sexpr
:= immediate-execution mode
Integer
:= (+I-] {digit}
Integers must be in the range -32767 through
32767. VJhen converting non-integers into
integers, APPLESOFT may be considered to
truncate the non-integer to the next smaller
integer. However, this is not quite true in
the limit as the non-integer approaches the next
larger Integer. For instance:
A% = 123.999 999 959 999 B7, = 123.999 999 96
PRINT A% PRINT B%
123 124
C% = 12345.999 995 999 D% = 12345.999 996
PRINT C% PRINT D%
12345 12346
(Spaces added £or easier reading)
An array integer occupies 2 bytes (16 bits) in memory.
integer variable name
: = name%
A real may be stored as an integer variable, but
APPLESOFT first converts the real to an integer.
letter
:=A|B|C|D|E|F|G|H|I|J|K|L|M|N|0|P|Q|R|S|T|U|V|W|X|Y|Z
line
:= llnenum [{instruction:}) instruction return
linenun
: = line number
:= digit [{digit}]
Line numbers must be in the range to 63999
or a '.'SYNTAX ERROR message is displayed.
literal
:= [{character}]
lower-case letter
:=a|b|c|d|e|f|g|h|i|j|k|l|m|n|o(p|q|r|s|t|u|v|w|x|y|z
metaname
:= {metasymbol} [digit]
145
raetasymbol
:= Characters used in this document to indicate
various structures or relationships in
APPLESOFT, but which are not part of the
language Itself.
:= ll(|]|{|}|\r
:= lower-case letter
:= a single digit concatenated to a raetaname
letter [{letter I digit )1
A name may be up to 238 characters in length. When
distinguishing one name from another, APPLESOFT
ignores any alphanumeric characters after the first
two. APPLESOFT does not distinguish between the
names G00D4LITTLE and GOLDRUSH. However, even the
ignored portion of a name must not contain a
special or any of APPLESOFT'S reserved words.
real variable name
narae%
:= Integer variable name
naraeS
;= string variable name
null string
op
:= operator
: = aop lalop
prompt character
real
The right bracket (]) is displayed when APPLESOFT
is ready to accept a command.
[+I-] {digit} [.{digit)) [ E[+|-]dlgit[digit] )
[+I-] [{digit}!, [{digit}) [ E[+|-]digit[digit] ]
The letter E, as used in real number notation
(a form of "scientific notation"), stands for
"exponent." It is shorthand for *10~
Ten is raised to the power of the number on
E's right, and number on E's left is multiplied
by the result.
In APPLESOFT, reals must be in the range -1E38
through 1E38 or you risk the TOVERFLOW ERROR
message. Using addition or subtraction, you
may be able to generate reals as large as
1.7E38 without receiving this message.
146
A real whose absolute value is less than about
2.9388E-39 will be converted by APPLESOFT to
zero.
APPLESOFT recognizes the following as reals when
presented by themselves, and evaluates them as zero:
+. -, .E +. E -.E
.E+ .E- +.E- +. E+ -.E+ -.E-
The array element M(.) is the same as M(0)
In addition to the abbreviated reals listed above,
the following are recognized as reals and evaluated
as zero when used as numeric responses to INPUT or
as numeric elements of DATA:
+ - E +E -E space
E+ E- +E+ +E- -E+ -E-
The GET instruction evaluates all of the single-
character reals in the above lists as zero.
When printing a real number, APPLESOFT will show
at most nine digits {see exception, below),
excluding the exponent (if any). Any further
digits are rounded off. To the left of the decimal
point, any zeros preceding the leftmost non-zero
digit are not printed. To the right of the decimal
point, any zeros following the rightmost non-zero
digit are not printed. If there are no non-zero
digits to the right of the decimal point, the
decimal point is not printed.
At the extreme limit, rounding is sometimes curious:
PRINT 99 999 999.9
99 999 999.9
PRINT 99 999 999.9(3
100 000 000
PRINT 11.111 111 451 9
11. HI 111 4
PRINT 11. lU 111 450 00
11.111 HI 5
(Spaces added for easier reading)
147
If a real's absolute value is greater than or
equal to .01 and less than 999 999 999.2 the
real Is printed In fixed-point notation.
That is, no exponent is displayed. In the range
.0 100 000 000 5 to .0 999 999 999
reals are printed with up to ten digits,
including the zero immediately to the right of the
decimal point. This is the only exception to the
liralt of nine printed digits, excluding the
exponent.
IE you attempt to use a real with more than 38
digits, such as
211. UlllUllllUlUl 1111111 11 lIllllU
then the message
?OVERFL0W ERROR
is printed, even if the real is clearly within
the range -1E38 through 1E38. This is true even
if most of the digits are trailing zeros, as in
2 U. 0000000000000000000000000000000000
Leading zeroes, however, are ignored. If the first
digit is a one, and the second digit is less than
or equal to six, numbers with 39 digits may be
used without getting an error message.
A real occupies 5 bytes (40 bits) in memory.
real variable name
: = name
reserved word
:= certain groups of characters used by APPLESOFT to
specify Instructions or portions of instructions.
A name must not include a reserved word. Refer to
Appendix G for a list of APPLESOFT'S reserved
words.
a press of the key marked "RESET"
:= a press of the key marked "RETURN"
sexpr
= string expression
= svar I string
= sexpr sop sexpr
slop
sop
:= string logical operator
:= string operator
:= +
148
special
:= special symbol used by APPLESOFT II
:= !|#|$|%|&n"l(l)l*l/n<l>l = l + |-|:|;l,|.|@l?ll
Control characters (characters which are typed
while holding down the CTRL key) and the null
characer are also specials. The right bracket ( )
can be typed on the APPLE keyboard, but APPLESOFT
uses it for the prompt character only* In this
document it is used as a metasymbol.
subscript
:= (aexpr [{,aexpr}] )
The maximum number of dimensions (aexpr 's)
is 89, although in practice this is limited
by the extent of memory available, aexpr
must be positive, and in use it is
converted to an Integer.
string
"({character}]"
A string occupies 2 bytes (16 bits) in memory
for its location pointer, plus 1 byte (8 bits)
for each character in the string,
"[{character}] return
This form of the string can appear only
at the end of a line.
string variable name
:= name?
string variable
name$|name$ subscript
The location pointer and variable name each occupy 2 bytes
in memory. The length and each string character occupy one byte.
:= variable
;= avar|svar
i := metasymbol used to separate alternatives
(note; an item may also be defined separately
for each alternative)
[ ] := metasymbols used to enclose material which
is optional
{ } := metasymbols used to enclose material which
may be repeated
\ : = metasymbol used to enclose material whose
value Is to be used: the value of x
is written \x\
:= metasymbol which Indicates a required space
149
Appendix O: Summary of APPLESOFT Commands
The inside back cover of this manual contains an alphabetical index
directing you to the more detailed descriptions of APPLESOFT commands
contained in Chapters 3 through 10.
ABS (-3.451 )
Returns the absolute value of the argument. The example returns 3.451.
arrow keys
The keys marked with right and left arrows are used to edit APPLESOFT
programs. The right-arrow key moves the cursor to the right; as it does,
each character it crosses on the screen is entered as though you had typed
it. The left-arrow key moves the cursor to the left; as it moves, one
character is erased from the program line which you are currently typing,
regardless of what the cursor is moving over.
ASCC'QUKST")
Returns the decimal ASCII code for the first character in the argument. In
the example, 81 (ASCII for Q) will be returned.
ATN(2)
Returns the arctangent, in radians, of the argument. In the example,
1.1(3714872 (radians) will be returned.
(JALl. -''iJ
Causes execution of a machine-language subroutine at the memory location
whose decimal address is specified. The example will cause a line feed.
CHR$(65)
Returns the ASCII character that corresponds to the value of the argument,
which must be between and 255. The example returns the letter A,
CLEAR
Sets all variables to zero and all strings to null.
C0LnR = 12
Sets the color for plotting in low-resolution graphics mode. In the
example, color is set to green. Color is set to zero by GR. Color names
and their associated numbers are
black 4 dark green 8 brown 12 green
1 magenta 5 grey 9 orange 13 yellow
2 dark blue 6 medium blue 10 grey 14 aqua
3 purple 7 light blue 11 pink 15 white
To find out the color of a given point on the screen, use the SCRN command.
150
CONT
If program execution has been halted by STOP, END, ctrl C or reset 0G
return, the CONT command causes execution to resume at the next
instruction (like GOSUB)-- not the next line number. Nothing is
cleared. After reset 0G return the program may not CONTlnue properly
because some program pointers and stacks are cleared. CONT cannot be used
if you have
a) modified, added or deleted a program line, or
b) gotten an error message since stopping execution.
COS (2)
Returns the cosine of the argument, which must be in radians. In the
example, -.415146836 is returned.
Ctrl C
Can be used to interrupt a RUNning program or a LlSTing. It can also be
used to interrupt an INPUT if it is the first character entered. The INPUT
is not interrupted until the RETURN key is pressed.
Ctrl X
Tells the APPLE II to ignore the line currently being typed, without
deleting any previous line of the same line number. A backslash (\) is
displayed at the end of the line to be ignored.
DATA JI5HN SMITH, "CODE 32", 2 J. 45, -6
Creates a list of elements which can be used by READ statements. In the
example, the first element is the literal JOHN SMITH; the second element is
the string "CODE 32"; the third element is the real number 23.45; the fourth
element is the integer -6.
DEF FN A(W)=2*W+W
Allows user to define one-line functions in a program. First the function
must be defined using DEF; later in the program the previously DEFined
function may be used. The example illustrates how to define a function
FN A(W); it may be used later in the program in the form FN AC23) or
FN A(-7*Q+1) and so on. FN A(23) will cause 23 to be substituted for W in
2*W+W: the function will evalute to 2*23+23 or 69. Assume Q=2; then
FN A(-7*Q+1) is equivalent to FN A(-7*2+l) or FN A(-13): the function will
evaluate to 2*(-13)+(-13) or -26-13 or -39.
DEL 23,56
Removes the specified range of lines from the program. In the example,
lines 23 through 56 will be DELeted from the program. To DELete a single
line, say line 350, use the form DEL 350,350 or simply type the line number
and then press the RETURN key.
151
DIM ACE(20,3), NAME$(50)
When a DIM statement is executed, it sets aside space for the specified
arrays with subscripts ranging from through the given subscript. In the
example, NAME$(50) will be allotted 50+1 or 51 strings of any length; the
array AGE(20,3) will be allotted (20+I)*(3+l) or 21*4 or 84 real number
elements. If an array element is used in a program before it is
DIMensloned, a maximum subscript of 10 is alloted for each dimension in the
element's subscript. Array elements are set to zero when RUN or CLEAR are
executed .
DKAV; 4 AT 50, 100
Draws shape definition number 4 from a previously loaded shape table, in
high-resolution graphics, starting at x=50, y=100. The color, rotation and
scale of the shape to be drawn must have been specified before DRAW is
executed.
END
Causes a program to cease execution, and returns control to the user. No
message is printed.
esc A ox_ esc B ££ esc C or_ esc D
The Escape key may be used in conjunction with the letter keys A or B or C
or D to move the cursor without affecting the characters moved over by the
cursor. To move the cursor one space, first press the escape key, then
release the escape key and press the appropriate letter key.
command moves cursor one space
esc A right
esc B left
esc C down
esc D up
EXP (2)
Returns the value of e raised to the power indicated by the argument. To 6
places, 6=2.718289, so in the example 7.3890561 will be returned.
FLASH
Sets the video mode to "flashing", so the output from the computer is
alternately shown on the TV screen in white characters on black and then
reversed to black characters on a white background. Use NORMAL to return to
a non-flashing display of white letters on a black background.
FOR U=l TO 20 . .. NEXT W
FOR Q'=2 TO -3 STEP -2 . . . NEXT Q
FOR Z=5 TO 4 STEP 3 . . . NEXT
Allows you to write a "loop" to perform a specified number of times any
instructions between the FOR command (the top of the loop) and the NEXT
command (the bottom of the loop). In the first example, the variable W
counts how many times to do the instructions; the Instructions inside the
152
loop will be executed for W equal to 1, 2, 3, ...26>, then the loop ends
(with W=21) and the Instruction after NEXT W is executed. The second
example illustrates how to indicate that the STEP size as you count is to be
different from 1. Checking takes place at the end of the loop, so in the
third example, the instructions inside the loop are executed once.
FRf:(a)
Returns the amount of memory, in bytes, still available to the user. What
you put Inside the parentheses is unimportant, so long as it can be
evaluated by APPLESOFT.
GET ANSS
Fetches a single character from the keyboard without showing it on the TV
screen and without requiring that the RETURN key be pressed. In the
example, the typed character is stored in the variable ANS$.
GOSUB 250
Causes Che program to branch to the indicated line (250 in the example).
When a RETURN statement is executed, the program branches to the statement
immediately following the most recently executed GOSUB.
GOTO 2 50
Causes the program to branch to the indicated line (250 in the example).
CR
Sets low-resolution GRaphics mode (40 by 40) for the TV screen, leaving four
lines for text at the bottom. The screen is cleared to black, the cursor is
moved into the text window, and COLOR is set to (black).
HC0L0R=4
Sets high-resolution graphics color to the color specified by HCOLOR.
names and their associted values are
blackl 4 black2
1 green (depends on TV) 5 (depends on TV)
2 blue (depends on TV) 6 (depends on TV)
3 whltel 7 white2
HGR
Only available in the firmware version of APPLESOFT. Sets high-resolution
graphics mode (280 by 160) for the screen, leaving four lines for text at
the bottom. The screen is cleared to black, and page 1 of memory is
displayed. Neither HCOLOR nor text screen memory is affected when HGR is
executed. The cursor is not moved into the text window.
HGR 2
Sets full-screen high-resolution graphics mode (280 by 192). The screen is
cleared to black and page 2 of memory is displayed. Text screen memory is
not affected.
153
HIMEM: 16384
Sets the address of the highest memory location available to an APPLESOFT
program, including variables. It Is used to protect an area of memory for
data, high-resolution screens or machine-language routines. HIMEM: is not
reset by CLEAR, RON, NEW, DEL, changing or adding a program line, or reset.
HLIN m, 20 AT 30
Used to draw horizontal lines in low-resolution graphics mode, using the
color most recently specified by COLOR. The origin (x=0 and y=0) for the
system is the top leftmost dot of the screen. In the example, the line Is
drawn from x=l(2 to x=20 at y=30. Another way to say this: the line is drawn
from the dot (10,30) through the dot (20,30).
HOME
Moves the cursor to the upper left screen position within the text window,
and clears all text in the window.
HPLOT Id, 20
HPLOT 30, 40 TO 50, 60
HPLOT TO 70, 80
Plots dots and lines in high-resolution graphics mode using the most
recently specified value of HCOLOR. The origin is the top leftmost screen
dot (x=0, y=0). The first example plots a high-resolution dot at x=10,
y=20. The second example plots a high-resolution line from the dot at x=30,
y=40 to the dot at x=50, y=60. The third example plots a line from the last
dot plotted to the dot at x=70, y=80, using the color of the last dot
plotted , not necessarily the most recent HCOLOR.
HTAB J i
Moves the cursor either left or right to the specified column (1 through 40)
on the screen. In the example, the cursor will be positioned In column 23.
IF A(;ii<18 THEN A-0: B=l: C = ^
IF ANS$="YES" THEN GOTO 100
IF N<MAX THEN 25
IF N<MAX GOTO 25
If the expression following IF evaluates as true (i.e. non-zero), then the
Instruction(s) following THEN in the same line will be executed. Otherwise,
any Instructions following THEN are Ignored, and execution passes to the
instruction in the next numbered line of the program. String expressions
are evaluated by alphabetic ranking. Examples 2, 3 and 4 behave the same,
despite the different wordings.
INPUT AZ
INPUT "TYPE AGE THEN A COMMA THEN NAME "; B, C$
In the first example, INPUT prints a question mark and waits for the user to
type a number, which will be assigned to the integer variable A.%. In the
154
second example, INPUT prints the optional string exactly as shown, then
waits for the user to type a number (which will be assigned to the real
variable B) then a comma, then string input (which will be assigned to the
string variable CS). Multiple entries to INPUT may be separated by commas
or returns.
INT(NUM)
Returns the largest Integer less than or equal to the given argument. In
the example, If NUM is 2.389, then 2 will be returned; if NUM is -45.123345
then -46 will be returned.
INVF.RSR
Sets the video mode so that the computer's output prints as black letters
on a white background. Use NORMAL to return to white letters on a black
background.
IN# 4
Specifies the slot (from 1 through 7) of the peripheral which will be
providing subsequent input for the computer. IN// re-establishes input
from the keyboard Instead of the peripheral.
LEFT$("APPLES()FT",51
Returns the specified number of leftmost characters from the string.
example, APPLE (the 5 leftmost characters) will be returned.
In the
left arrow
See "arrow keys".
LENC'AN APPLE A [)AY")
Returns the number of characters In a string, between and 255.
example, 14 will be returned.
1 1-: T A = :m . 'i fi 7
A$ = "DELICIOUS"
The variable name to the left of
expression to the right of the =
is assigned the value of the string or
The LET is optional.
LIST
LIST 2(30-3^0
LIST 2(J(J, 300(3
The first example causes the whole program to be displayed on the TV screen;
the second example causes program lines 2(il0 through 300(3 to be displayed.
To list from the start of the program through line 200, use LIST -200 ; to
list from line 200 to the end of the program, use LIST 200- . The third
example behaves the same as the second example. LISTing is aborted by Ctrl
C.
iss
LOAD
Reads an APPLESOFT program from cassette tape into the computer's memory.
No prompt is given: the user must rewind the tape and press "play" on the
recorder before LOADing. A beep is sounded when Information is found on the
tape being LOADed. When LOADing Is successfully completed, a second beep
will sound and the APPLESOFT prompt character (]) will return. Only reset
can interrupt a LOAD.
L(w;(2)
Returns the natural logarithm of the specified arithmetic expression. In
the example, .693147181 Is returned-
LOHEM: 2060
Sets the address of the lowest memory location available to a BASIC program.
This allows protection of variables from high-resolution graphics in
computers with large amounts of memory.
MIDS("AN APPLK A DAY", 4)
MID$("AN APPLE A DAY", 4, 9)
Returns the specified substring. In the first example, the fourth through
the last characters of the string will be returned: APPLE A DAY. In the
second example, the nine characters beginning with the fourth character in
the string will be returned: APPLE A D
NEW
Deletes current program and all variables.
NEXT
See the discussion of FOR. . .TO.. .STEP.
NORMAL
Sets the video mode to the usual white letters on a black background for
both input and output.
NOTRACE
Turns off the TRACE mode. See TRACE.
OS ID GOSUB 100, 200, 23, 4005, 500
Executes a GOSUB to the line number indicated by the value of the arithmetic
expression following ON. In the example, if ID is 1, GOSUB 100 is executed;
if ID is 2, GOSUB 200 is executed, and so on. If the value of the
expression is or is greater than the number of listed alternate line
numbers, then program execution proceeds to the next statement.
ON ID GOTO 100, 200, 23, 4005, 500
Identical to ON ID GOSUB (see above), but executes a GOTO branching to the
line number indicated by the value of the arithmetic expression following
ON.
156
ONERR COTO 501/)
Used to avoid an error message that halts execution when an error occurs.
When executed, ONERR GOTO sets a flag that causes an unconditional jump to
the Indicated line number (500, in the example) if any error Is later
encountered.
PDI. (3)
Returns the current value, a number from through 255, of the indicated
game control paddle. Game paddle numbers through 3 are valid.
PEEK(37)
Returns the contents, in decimal , of the byte at the specified decimal
address (37 in the example).
PLOT 10, 1^
In low-resolution graphics mode, places a dot at the specified location,
the example, the dot will be at x=10, y=20. The color of the dot is
determined by the most recent value of COLOR, which is (black) if not
previously specified.
POKE -163(32,
Stores the binary equivalent of the second argument (0, In the example) into
the memory location whose decimal address is given by the first argument
(-16302, in the example).
POP
Causes one RETURN address to "pop" off the top of the stack of RETURN
addresses. The next RETURN encountered after a POP causes a branch to one
statement beyond the second most recently executed GOSUB.
I'OK(GI)
Returns the current horizontal position of the cursor- This is a number
from (at the left margin) to 39 (at the right margin). What you put
inside the parentheses is unimportant, so long as it can be evaluated by
APPLESOFT.
PR [ NT
PRINT A$; "X = "; X
The first example causes a line feed and return to be executed on the
screen. Items in a list to be PRINTed should be separated by commas if each
is to be displayed in a separate tab field. The items should be separated
by semi -colons if they are to be printed right next to each other, without
any intervening space. If A$ contains "CORE" and X is 3, the second example
will cause
COREX = 3
to be printed.
157
PR* 2
Transfers output to the specified slot, 1 through 7. PR# returns output
to the TV screen.
RKAD A, B; , IS
When executed, assigns the variables in the READ statement successive values
from elements in the program's DATA statements. In the example, the first
two elements in the DATA statements must be numbers, and the third a string
(which may be a number). They will be assigned, respectively, to the
variables A, B%, and C3.
K1-:CALL MX
Retrieves a real or an integer array which has been STOREd on cassette tape.
An array may be RECALLed with a different name than used when it was STOREd
on the tape. When RECALLed, MX must have been DIMensioned by the program.
Subscripts are not used with either STORE or RECALL: in the example, the
array whose elements are MX(0), MX(1), ... will be retrieved; the
subscriptless variable MX will not be affected. No prompt or other signal
is given: you must press "play" on the recorder when RECALL is executed;
"beeps" signal the beginning and end of the recorded array. Only reset can
interrupt a RECALL.
RHM THIS A REMARK
Allows text to be Inserted into a program as remarks.
repeat
If you hold down the repeat key, labeled REPT, while pressing any character
key, the character will be repeated.
KESTORl'
Resets the "data list pointer" to the first element of DATA. Causes the
next READ statement encountered to re-READ the DATA statements from the
first one.
RESUME
At the end of an error-handling routine (see ONERR GOTO), causes the
resumption of the program at the statement In which the error occurred.
Rl'/FLRN
Branches to the statement immediately following the most recently executed
RIGHTS("SCRAPPI,E",5)
Returns the specified number of rightmost characters from the string. In
the example, APPLE (the 5 rightmost characters) will be returned.
riRht arrow
See "arrow keys".
158
RND(5)
Returns a random real number greater than or equal to and less than 1.
RND(0) returns the most recently generated random number. Each negative
argument generates a particular random number that is the same every time
RND Is used with that argument, and subsequent RND's with positive
arguments will always follow a particular, repeatable sequence. Every time
RND IS used with any positive argument, a new random number from to 1 is
generated, unless it is part of a sequence of random numbers initiated by a
negative argument.
ROT =16
Sets angular rotation for shape to drawn by DRAW or XDRAW. ROT=0 causes
shape to be DRAWn oriented Just as it was defined, R0T=16 causes shape to
be DRAWn rotated 90 degrees clockwise, etc. The process repeats starting at
ROT =6 4.
RUN 500
Clears all variables, pointers, and stacks and begins execution at the
indicated line number (500 in the example). If no line number is specified,
execution begins at the lowest numbered line in the program.
SAVE
Stores a program on cassette tape. No prompt or signal is given: the user
must press "record" and "play" on the recorder before SAVE is executed.
SAVE does not check that the proper recorder buttons are pushed; "beeps"
signal the start and end of a recording.
SCALE=50
Sets scale size for shape to be drawn by DRAW or XDRAW. SCALE=1 sets point
for point reproduction of the shape definition. SCA1.E=255 results in each
plotting vector being extended 255 times. NOTE: SCALE=0 is maxlmlm size
and not a single point.
SCKN( 10, 20)
In low-resolution graphics mode, returns the color code of the specified
point. In the example, the color of the dot at x=10, y=20 is returned.
SGN(NUM)
Returns -1 if the argument is negative, if the argument is 0, and 1 if the
argument Is positive.
SHLOAD
Loads a shape table from cassette tape. Shape table is loaded just below
HIMEM: and then HIMEM: is set to just below the shape table to protect it.
SIN (2)
Returns the sine of the argument, which must be in radians. In the example,
.909297427 Is returned.
159
SPC(8)
Must be used in a PRINT statement. Introduces the specified number of
spaces (8, in the example) between the last item PRINTed and the next item
PRINTed if semi-colons precede and follow the SPC command.
SPEED = 50
Sets rate at which characters are to be sent to the screen or other
input/output devices. The slowest rate is 0; the fastest is 255.
SQR(2)
Returns the positive square root of the argument; in the example, 1.41421356
Is returned. SQR executes more quickly than ~.5
STOP
Causes a program to cease execution and display a message telling what line
number contained the STOP. Control of the computer is returned to the user.
STORE MX
Records an integer or real array on tape. No prompt message or other signal
is provided: the user must press "record" and "play" on the recorder when
STORE is executed. "Beeps" signal the beginning and end of the recording.
The subscript of the arrray is not indicated vjhen STORE is used. In the
example, the elements MX(0), MX(1), HX(2), ... are saved on the tape; the
variable MX is not affected. See RECALL.
STR«(12.45)
Returns a string that represents the value of the argument. In the example,
the string "12.45" is returned.
TAB(23)
Must be used in a PRINT statement; the argument must be between and 255
and enclosed in parentheses. For arguments 1 through 255, if the argument
is greater than the value of the current cursor position, then TAB moves the
cursor to the specified printing position, counting from the left edge of
the current cursor line. If the argument is less than the value of the
current cursor position, then the cursor is not moved. TAB(0) puts the
cursor Into position 256.
TAN (2)
Returns the tangent of the argument, which must be in radians. In the
example, -2.18503987 is returned.
TEXT
Sets the screen to the usual non-graphics text mode, with 40 characters per
line and 24 lines. Also resets the text window to full screen.
160
TRACE
Causes the line number of each statement to be displayed on the screen as it
is executed. TRACE is not turned off by RUN, CLEAR, NEW, DEL or reset.
NOTRACE turns off TRACE.
USR(3)
This function passes its argument to a machine-language subroutine. The
argument is evaluated and put into the floating-point accumulator (locations
$9D through $A3), and a JSR to location $0A is performed. Locations $0A
through $0C must contain a JMP to the beginning location of the
machine-language subroutine. The return value for the function is placed In
the floating-point accumulator. To return to APPLESOFT, do an RTS.
VAL("-3. 7E4A5PLE")
Atterapts to interpret a string, up to the first non-numeric character, as
real or an Integer, and returns the value of that number. If no number
occurs before the first non-numeric character, a is returned. In the
example, -376130 is returned.
VLIN 10,20 AT 30
In low-resolution graphics mode, draws a vertical line in the color
indicated by the most recent COLOR statement. The line is drawn in the
column indicated by the third argument. In the example, the line is drawn
from y=10 to y=2(il at x=30.
VTAB(15)
Moves the cursor to the line on the screen specified by the argument. The
top line is line 1; the bottom line Is line 24. VTAB will move the cursor
up or down but not left or right.
WAIT 16000, 255
WAIT 160(30, 255,
Allows a conditional pause to be inserted into a program. The first
argument is the decimal address of a memory location to be tested to see
when certain bits are high (1, or on) and certain bits are low (0, or off).
Each bit in the binary equivalent of the decimal second argument Indicates
whether you're Interested in the corresponding bit in the memory location: 1
means you're interested, means ignore that bit. Each bit in the binary
equivalent of the decimal third argument indicates which state you're
WAITing for the corresponding bit in the memory location to be in: 1 means
the bit must be low, means the bit must be high. If no third argument is
present, is assumed. If any one of the bits indicated by a 1-bit in the
second argument matches the state for that bit indicated by the
Corresponding bit in the third argument, the WAIT is over.
XDRAW 3 AT 180, 120
Draws shape definition number 3 from a previously loaded shape table, in
high-resolution graphics beginning at x=180, y=120. For each point plotted,
the color is the complement of the color already existing at that point.
Provides an easy way to erase: if you XDRAW a shape, then XDRAW it again,
you'll erase the shape without erasing the background.
161
INDEX
ABS 102, 150
Absolute value function: see ABS
Accuracy in digits 4, 5, 7, 18
Address 40, 41, 43-45
aexpr 34, 134
alop 33, 134
Alphanuraeric character 30, 134
AND 33, 36, 144
aop 33, 144
APPLESOFT BASIC
loading 106-109
converting to 124, 125
versus Integer BASIC 142, 143
in firmware 44, 106, 107, 109
on cassette 106, 108, 109
Arctangent function: see ATN
Arccosecant function 103
Arccosine function 103
Arccotangent function 103
Arcsecant function 103
Arcsine function 103
Arithmetic operators 33, 36
Arrays 14, 18, 32, 58
memory allocation 119
memory map 126, 127
STORE, RECALL 62-64
saving space 118, 119
zero page 140, 141
Arrow keys 54, 55, 110-114,
ASC 60, 150
ASCII character codes 138
Assertion 9
Assignment statement 8
Asterisk 2, 107
AT 6, 25, 86, 98, 152, 154, 161
ATN 18, 102, 123, 150
avar 33, 34, 144
B
150
BASIC loading 106-109
Branching
GOSUB 15, 16, 79, 8?
GOTO 76, 153
loops U-14, 78, 79
153
CALL 43, 52, 130, 134, 150
Cassette
arrays 62-64
shape tables 97
loading APPLESOFT 106, 108
memory range 118
Change program line 54, 110-114
Character 7, 30
ASCII codes 138, 139
strings 19-21, 59-61
CHR? 60, 150
CLEAR 8, 52, 150
Colon 10, 125
DATA 68
GET 68
INPUT 66
COLOR 5, 11, 24, 25, 85, 150
Color 23-27, 85, 89, 131-134
Columns: see tab fields
Comma
DATA 68
GET 68
INPUT 66
PRINT 6, 70
Command 2, 122-123
Concatenation
converting to APPLESOFT 124
PRINT 71
SPC 52
strings 21, 71
CONT 39, 40, 67, 151
Control character codes 128
Control B 106-108
Control C 7, 10, 35, 39, 40,
107-109, 151
DATA 68
GET 67
INPUT 66
LIST 48
Control H 67
Control M 66, 69
Control X 55, 66, 69, 151
Converting to APPLESOFT 124, 125
Cosecant function 103
COS 18, 102, 151
162
Cosine function: see COS
Cotangent function 103
Ctrl (Control) 35, 144
Cursor position 50-52, 54, 55,
110-114, 131
n
DATA 17, 68, 69, 141, 151
Debug mode 40
Decimal places 18, 22
Decimal tokens for keywords 121
DEF 18, 73, 74, 151
Deferred execution 2, 36, 134
DEL 49, 151
Delay loop 27, 41-43, 97
Delete 3, 38, 49
Delimiter 33, 144
Differences between APPLESOFT and
Integer BASIC 142, 143
Digits 4, 5, 18, 22
real numbers 31-33
DIM 14, 58, 152
Dimensions: see DIM
Division 2, 18, 33, 36
DRAW 92, 97-99
Dummy variable 73
Editing 54, 55, 110-114
Element
arrays 14, 32, 58, 62-64
DATA 68, 69
END 16, 39, 118, 152
Equals sign 9, 12
Erasing
programs 3, 38
the screen 52
Error 115-117, 167
ONNERRGOTO code type 81, 136
ESC 35
esc A, B, C, D
esc E, F 130
Execution 2, 36, 38-45
EXP 18, 103, 152
54, 110-114
Firmware APPLESOFT 106, 107, 109
Fixed point notation 4
FLASH 53, 152
Floating point notation 4, 120, 141
FN 73, 74, 151
Format 4-6, 18, 22
FOR. ..NEXT 11-14, 20, 78, 79, 152
Full screen graphics 84, 131-134
Function 73, 102-104
FRE 33, 153
Game controls 90, 134, 135
GET 24, 67, 153
GOSUB... RETURN 15, 16, 79, 80,
119, 153
GOTO 7, 76, 81, 153
program speed 120
GR 5, U, 23-25, 84, 131-134, 153
Graphics 5, 10, 23-27, 83-100,
126, 131-134
Exponent 4, 5, 18, 31-33
Exponent function: see EXP
expr 35, 145
H
HCOLOR 26, 27, 89, 134, 153
Hexadecimal codes 138, 139
HGR 25, 26, 84, 87, 89, 98, 99,
153
HGR2 25, 84, 88, 89, 99, 153
High-resolution graphics 25-27,
87-100, 131-134
memory range 126
zero page 141
HIMEM: 41, 43, 44, 99, 100, 123,
127, 154
HLIN 6, 25, 86, 154
HOME 11, 48, 52, 154
HPLOT 26, 89, 98, 131-134, 154
HTAB 27, 50, 51, 154
Hyperbolic functions 103, 104
IF... GOTO 76, 154
IF... THEN 9-10, 76, 154
Immediate execution 2, 36
Incrementing in loops 13, 7^
163
INPUT 7, 9, 66, 67, 141, 154
Input/Output 38, 62-74, 126
game controls and speaker
9(3, 134-135
Inserting
pauses 41, 42
text 3, 113, 114
INT 19, 102, 155
Integer 2, 4
calculations 36
INT function 19, 102, 155
rounding 18, 31
variables 18, 31, 145
Integer BASIC versus APPLESOFT
142, 143
Internal routines 18, 102, 103,
119
Interrupting execution 39, 40
INVERSE 53, 155
Inverse hyperbolic functions 10-
Inverse trigonometric functions
102, 103
IN# 71, 155
Iteration 11-14
Keyboard 130
Keyword codes 121
LEFT$ 20, 60, 124, 155
Left-arrow key 54, 55, 67,
110-114, 150
LEN 19, 59, 155
LET 8, 12, 72, 155
Line 2, 3, 36, 118, 141
Lines in graphics mode 86, 89, 92-97
Line feed 70, 130
Line number 2, 3, 35, 49, 145
byte size 118
DATA 68
GOTO 76
LIST 48
ON... GOTO 81
zero page 140
linenum 35, 145
LIST 3, 4, 48, 155
Literal 19, 34, 145
DATA 68, 69
INPUT 66
LET 72
125
LOAD 38, 156
Loading BASIC 106-109
Logarithm function: see LOG
LOG 18, 103, 156
LOMEM: 44, 45, 123, 127, 156
Looping 11-14, 20; see FOR. . .NEXT
Low-resolution graphics 84-87
M
Machine language subroutines
45, 92-97
Mantissa 4
Margin settings 128, 129
MAT conversion to APPLESOFT
Matrix: see Array
Memory 2, 8, 40,
error message
HGR 87
HGR2 88
map 126, 127
remaining 53
storage allocation
zero page 140, 141
metaname 30, 145
metasymbols 30, 145
M1D$ 20, 61, 156
converting to APPLESOFT
MOD 104
Modes
debug 40
execution 36
Monitor
41
location
119
124
memory range 126, 127
le
55,
return to BASIC 107,
shape tables 92-97
zero page 140, 141
Moving the cursor 50-52, 54,
110-U4, 131
Multiple statements per line
10, 125
Multiplication 2, 33, 36
N
name, nanie%, name$ 31, 33, 34, 146
NEW 3, 8, 38, 156
NEXT 11-14, 20, 78, 79, 120,
NORMAL 53, 156
NOT 33, 34, 36
NOTRACE 40, 156
156
164
Null string 19
ASC 60
DATA 69
IF... THEN 76, 77
INPUT 66
MIDS 61
Number 4, 5, 18, 19, 31-33
Number format 4, 5, 18, 22, 31-33
ON...GOSUB 81, 156
ON... GOTO 81, 156
ONERRGOTO 81, 136, 141, 157
op 34, 146
OR 33, 36
Output , video modes 53
Pause 27, 41-43, 97
PDL 90, 157
PEEK 40, 131, 134-136, 157
Peripheral devices 71, 72, 90,
126, 134, 135
PLOT 5, 10, 24, 85, 157
Plotting 5, 10, 11, 23-27, 84-100,
131-134
POKE 41, 48, 128, 129, 131-136,
157
full screen graphics 84, 87,
88, 131-134
Pointers 38, 52, 69, 70, 80, 126,
127, 140, 141
POP 80, 157
POS 51, 157
Precedence of operators 36
Program 2
zero page pointers 140, 141
PRINT 2, 6, 7, 70, 71, 157
strings 20, 21
TAB 51
SPC 52
Prompt character 35, 84, 106, 108
PR# 72, 158
Question mark
INPUT 7, 66, 67
PRINT 70
Quotation mark
DATA 69
INPUT 66
strings 19, 34
Random number function: see RND
READ 17, 68-70, 141, 158
Real 4, 5, 31-33
calculations IB, 36
DATA 68, 69
variable names 18, 33
RECALL 62-64, 158
Relation between expressions 9, 36
REM 8, 10, 50, 118, 158
Repeat key (REPT) 55, 111-114, 158
Replacing lines 3
Reserved words 7, 8, 38, 64, 87,
148
list 122-123
storage allocation 119
Reset 35, 39, 40
HIMEM: 43, 44
LOtlElI: 44
RECALL 64
RESUME 82
stopping a program 39
STORE 64
RESTORE 17, 70, 158
RESUME 82, 158
return (RETURN key) 2, 3, 7, 33
GET 68
INPUT 66, 67
PRINT 70
RETURN 15, 16, 79, 80, 158
RIGHTS 20, 61, 158
Right-arrow key 54, 55, 110-114,
150
RND 18, 27, 102, 141, 159
ROM-APPLESOFT 106, 107, 109
ROT 92, 97-99 159
Rounding 4, 5, 18, 19, 31-33
RUN 2, 8, 38, 39, 159
SAVE 38, 159
Saving program space 118-119
SCALE 92, 97-99, 159
Scientific notation 4, 5
SCRN 87, 159
Secant 103
sexpr 35, 148
Semi-colon 30, 33
INPUT 66, 67
PRINT 6, 70, 71
\m
SGN 102, 159
Shapes 92-100
SHLOAD 92, 97
Significant dig
Slgnum: see SGN
SIN 18, 102, 1
Slash 2, 36
slop 35, 148
Slots thru 7
sop 34, 148
Sorting 15, 23
Space savers 1
SPC 52, 160
Speaker 134, 1
Special symbols
SPEED 54, 160
Speeding up the
SQR 11-13, 18,
Square root fun
STEP 13, 78, 1
STOP 16, 39, 1
Stopping a prog
39
Storage allocat
STORE 62-64, 1
STR$ 21, 22, 5
Strings 18-23,
ASC 60, 15
CHRS 60, 1
concatenati
converting
124, 125
DATA 68, 6
IF... THEN
INPUT 65,
LEFT$ 20,
LEN 19, 20
LET 72, 15
memory 53,
141
MIDS 20, 2
null string
69, 76, 7
RECALL 62
RIGHT$ 20,
STORE 62-6
STR$ 21, 2
substring
VAL 21, 23
Subroutine 16,
Subscript 14,
Substring 60,
100, 159
its 5
59
71, 72
18, 119
35
30
program 120
102, 160
ction: see SQR
52
60
ram 7 , 1
119
16, 38,
9, 160
34
50
on 21, 52, 71
to APPLESOFT
9, 151
76, 154
67, 154, 155
60, 155
, 59, 155
5
119, 126, 127, 140,
1, 61, 156
s 19, 60, 61, 67,
7
64, 158
61, 158
4, 160
2, 59, 160
60, 61
, 59, 161
22, 79, 80
15, 34, 58
61
svar 34, 149
Syntactic definitions 30-36
alphabetized 144-149
Tab
fields 70, 71
HTAB 50, 51
TAB 51, 160
VTAB 50
TAN 18, 102, 160
Tangent function: see TAN
TEXT 6, 11, 84, 160
Text 6, 24
and graphics 11, 131-134, 160
memory range 126
window 50, 51, 70, 71, 84,
128-130
THEN: see IF. . .THEN
TO: see HPLOT and GOTO
Tokens for keywords 121
TRACE 40, 82, 161
Trigonometric functions 18, 102-104
u
USR 45, 161
VAL 21, 23, 59, 161
var 35
Variables 7, 8, 31-35
array 14, 58
FOR... NEXT loops 12, 13, 78,
79
INPUT 7, 9, 66, 67, 71
integer 18, 19, 31
LET ( = ) 8, 12, 14, 72, 73
names 7, 8, 14, 18 31-35
program speed 120
READ, DATA 17, 68-70
real 18
saving space 118, 119
string 18
zero page 140, 141
Vector 92-96
Video output 53
VLIN 6, 25, 85, 161
VTAB 27, 50, 161
166
w
WAIT 41, 42, 161
Window 50, 51, 78, 84, 128, 129
XDRAW 92, 97-99, 161
XPLOT 123
Zero page 140, 141
ERROR MESSAGES
?BAD SUBSCRIPT 117
DIM 58
ICAtn CONTINUE 115
CONT 40
7DIVISI0N BY ZERO 115
?EXTRA IGNORED
GET 68
INPUT 67
?FORMULA TOO COMPLEX 116
IF 77
?1LLEGAL DIRECT 115
INPUT 67
71LLEGAL QUANTITY 115
ASC 60
CALL 43
CHR$ 60
DRAW 93 .
HIMEM; 43
HPLOT 89
HTAB 50
IN// 72
LEFT$ 60
MID? 61
ON...GOSUB 81
ON... GOTO 81
PDL 90
PLOT 85
POKE 41
RIGHT $ 61
SPC 52
SPEED 54
STORE, RECALL 62
VEIN 86
VTAB 50
WAIT 41
7NEXT WITHOUT FOR 116
FOR 78
NEXT 79
?OUT OF DATA 116
READ 70
RECALL 64
STORE 64
TOUT OF MEMORY 116
DIM 58
GOSUB 79
HIMEll: 44
LOMEM: 44
?OVERFLOW ERROR 116
reals 33
SIRS 5 9
VAL 59
?REDIM'D ARRAY 116
DIM 58
7REENTER
INPUT 66
7RETURN WITHOUT GOSUB 116
RETURN 80
7STRING TOO LONG ERROR Uf
LEN 59
PRItiT 71
VAL 59
? SYNTAX ERROR 117
ASC 60
CONT 40
DATA 69
DEL 49
FOR... NEXT 78, 79
GET 68
HGR 88
HGR 2 88
IF... THEN 76, 77
INPUT 67
LIST 48
RECALL 64
RESUME 82
RUN 1 1 1
SHLOAD 100
STORE 64
TEXT 84
?TYFE MISMATCH 117
LEFTS 60
LET 73
MID$ 61
RIGHTS 61
?UNDEF'D FUNCTION 117
DEE 74
?UNDEF'D STATEMENT 117
GOSUB 79
GOTO 76
RUN 38
1*57
CAST OF CHARACTERS
II
9, 30, 3A, 66, 67, 69, 71
$
18, 30, 34, 60, 61
%
18, 30, 31
*
2, 30, 36. 106
+
A, 5, 30, 32, 36, 65, 68
-
4, 5, 30, 32, 36, 66, 68
5
2, 6, 30, 33, 66-71
/
2, 30, 33, 36, 125
30, 33, 66-69
;
6, 30, 33, 66, 67, 70, 71
9
7, 30, 65, 70
\
30
]
vi, 30, 35, 106
•^
30, 33, 36
1
30
~
30, 33
14, 30, 33, 119
(]
vli, 30
<}
vil, 30
=
as assignment 8, 12
>
as prompt character 106
~i
>, < 9, 30, 33, 36
&
123
168
Alphabetic Index to
APPLESOFT BASIC Commands
Command
Pag(
ABS
102
arrow
keys
55
ASC
60
ATN
102
CALL
43
CHRS
60
CLEAR
52
COLOR
85
CONT
39
COS
102
Ctrl C
39
Ctrl X
55
DATA
68
DEF FN
73
DEL
A9
DIM
58
DRAW
98
END
39
esc A
54
esc B
54
esc C
54
esc D
54
EXP
103
FOR...
TO...
STEP
78
FLASH
53
FRE
53
GET
67
GOSUB
79
GOTO
76
GR
84
HCOLOR
89
HGR
87
HGR2
88
HIMEM:
43
HLIN
86
Command
Pa^,
HOME
52
HPLOT
89
HTAB
50
IF. ..
GOTO
76
IF. ..
THEN
76
INPUT
66
IHT
102
INVERSE
53
IN#
71
LEFT?
60
left
arrow
55
LEN
59
LET
72
LIST
48
LOAD
38
LOG
103
LOMEM:
44
MIDS
61
NEW
38
NEXT
79
NORMAL
53
NOTRACE
40
ON. ..
GOSUB
81
ON...
GOTO
81
ONERR
GOTO
81
PDL
90
PEEK
40
PLOT
85
POKE
41
POP
80
POS
51
PRINT
70
Command
Pa^e
PR#
72
READ
69
RECALL
62
REM
50
repeat
55
reset
39
RESTORE
70
RESUME
82
RETURN
80
RIGHT?
61
risht
arrow
55
ROT
99
RND
102
RUN
38
SAVE
38
SCALE
99
SCRN
87
SGN
102
SHLOAD
99
SIN
102
SPC
52
SPEED
54
SQR
102
STEP
78
STOP
39
STORE
62
STRS
59
TAB
51
TAN
102
TEXT
84
TRACE
40
USR
45
VAL
59
VLIN
86
VTAB
50
UAIT
XDRAW
98
^appkz computer inc.
10260 Bandley Drive
Cupertino. California 95014
(408] 996-1010